Javascript 如何理解;“拥有自己的财产”;及__原型;在Js中?
在ECMAScript中,没有对象的Javascript 如何理解;“拥有自己的财产”;及__原型;在Js中?,javascript,v8,Javascript,V8,在ECMAScript中,没有对象的\uuuu proto\uuu: Array.hasOwnProperty('prototype') //true var arr = new Array() arr.hasOwnProperty('__proto__') //false 然后,我们可以发现: Object.getOwnPropertyDescriptors(arr) 输出: length:{value: 1, writable: true, enumerable: fa
\uuuu proto\uuu
:
Array.hasOwnProperty('prototype') //true
var arr = new Array()
arr.hasOwnProperty('__proto__') //false
然后,我们可以发现:
Object.getOwnPropertyDescriptors(arr)
输出:
length:{value: 1, writable: true, enumerable: false, configurable: false}
__proto__:Object
因此,我感到困惑:
arr
是否有自己的财产\uuuuuuuuuuuuu
当我尝试做以下事情时:
arr.unshift("2")
Js引擎在哪里找到unshift
方法
是否有任何信息让Js引擎查找unshift
Js引擎在哪里找到unshift方法
在Array.prototype
上,从中继承arr
。每个对象上都有一个内部原型链链接,通常称为[[prototype]]。您可以使用
因此,我感到困惑:arr是否有自己的财产
不,\uuu proto\uu
是从对象继承的setter/getter。prototype
,它不是自己的属性。(不过,您可以在arr中找到“\uuuuuu proto\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu”)。和。最好忘了它
为什么Object.getOwnPropertyDescriptors(arr)
会输出一个\uuuuuuuuuuuuuuuu
因为控制台使用这个名称来表示内部原型链接getOwnPropertyDescriptors
返回一个对象,该对象自然继承自object.prototype
。没什么特别的。您也可以在空对象{}
中找到它。unshift
是数组的一个属性。prototype
@PHPglue但是arr
没有名为uuu protou_u
的属性,JsEngine如何查找数组。prototype.unshift
来自arr
?var arr=[]代码>是数组的新实例。数组具有从Array.prototype
继承的方法,但它们不是自己的属性。数组属性应为数字索引。可能重复
Object.getPrototypeOf(arr) == Array.prototype