gpt4 book ai didi

javascript - 为什么 Object.getOwnPropertyNames() 也给出了原型(prototype)上的方法?

转载 作者:行者123 更新时间:2023-12-01 02:44:13 25 4
gpt4 key购买 nike

var properties = Object.getOwnPropertyNames(Array); 
console.log(properties);

为什么这段代码也列出了 Array.prototype 对象的属性?根据我的理解,它应该列出直接在 Array 对象上找到的这些属性:

Array.length
Array.constructor
Array.prototype
Array.isArray
Array.of
Array.observe
Array.from
Array.unobserve

最佳答案

您必须使用 Firefox。它确实实现了 Array 构造函数的非标准扩展,其中 generics function are available as static methodsArray本身上。它们是自己的属性,与 Array.prototype 上的属性具有相同的名称,但值不同。它们不存在于其他浏览器中并且 won't be in future Firefoxes要么。

关于javascript - 为什么 Object.getOwnPropertyNames() 也给出了原型(prototype)上的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47368927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com