原型链里 [[Prototype]] 和 __proto__ 有什么区别?

[[Prototype]]和__proto__有什么区别,为什么下面就用了__proto__
原型链里 [[Prototype]] 和 __proto__ 有什么区别?


回答:

[[Prototype]]可以参见一个叫Symbol的新类型,这里就叫符号吧。通常无法通过索引或者"."进行访问的,Object.getPrototypeOf应该是正经的访问器。
__proto__是非标准的属性。
两者都是指向原型的。
https://developer.mozilla.org...


回答:

[[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 。


回答:

‘__proto__’ 是隐式原型
实例对象的隐式原型 === 构造函数的显式原型
即: fn.__proto__ === Fn.prototype

以上是 原型链里 [[Prototype]] 和 __proto__ 有什么区别? 的全部内容, 来源链接: utcz.com/p/937495.html

回到顶部