[[Prototype]]和__proto__有什么区别,为什么下面就用了__proto__
[[Prototype]] 是 internal slot 。
Internal slots correspond to internal state that is associated with objects and used by various ECMAScript specification algorithms. Internal slots are not object properties and they are not inherited. Depending upon the specific internal slot specification, such state may consist of values of any ECMAScript language type or of specific ECMAScript specification type values. Unless explicitly specified otherwise, internal slots are allocated as part of the process of creating an object and may not be dynamically added to an object. Unless specified otherwise, the initial value of an internal slot is the value undefined. Various algorithms within this specification create objects that have internal slots. However, the ECMAScript language provides no direct way to associate internal slots with an object.
internal slot 是对象的内部状态,外部无法直接访问与修改。
[[Prototype]] 这一个 internal slot 记录了对象的原型对象。javascript 提供了 Object.GetPrototypeOf 跟 Object.SetPrototypeOf 两个函数用来读取和设置它的值。
__proto__
是定义在 Object.prototype
上的一个 getter / setter (非标准)。它会去调用 Object.GetPrototypeOf 跟 Object.SetPrototypeOf 。
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答5.1k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决
[[Prototype]]可以参见一个叫Symbol的新类型,这里就叫符号吧。通常无法通过索引或者"."进行访问的,Object.getPrototypeOf应该是正经的访问器。
__proto__是非标准的属性。
两者都是指向原型的。
https://developer.mozilla.org...