What Internal Property In ECMAScript is defined for?

后端 未结 4 1667
-上瘾入骨i
-上瘾入骨i 2020-12-05 20:58

What the Internal Property in ECMAScript is defined for ? What does the spec mean by

This specification uses various internal properties to define th

4条回答
  •  攒了一身酷
    2020-12-05 21:21

    The often used example is the internal property [[prototype]], all objects have one but you can't access it directly eg.

    function foo(){
        this.first = "hi"
        this.second = something
    }
    foo.prototype = {
        constructor : foo,
        anotherProp : "hello"
    }
    
    var obj = new foo();
    
    console.log(obj.anotherProp); //hello
    //here the runtime will look in obj for anotherProp and
    //fail to find it so it will look in obj's internal property
    //[[prototype]] which is pointing to the object foo.prototype
    

    so you can access the objects that the internal property [[prototype]] is pointing to but not directly through the internal [[prototype]] property that is only for the runtime to use, not the programmer.

提交回复
热议问题