gpt4 book ai didi

javascript - 为什么我可以在 Array 属性对象中找到 Javascript Array forEach 方法?

转载 作者:行者123 更新时间:2023-11-28 13:16:45 25 4
gpt4 key购买 nike

我正在使用函数 Reflect.ownKeys(Array)) 处理 ECMAScript 6。我得到的属性是:

  console.log(Reflect.ownKeys(Array))
["length", "name", "arguments", "caller", "prototype", "isArray", "from", "of", Symbol(Symbol.species)]

但我仍然可以在数组上使用 forEach 方法!但我找不到定义函数 forEach 的位置,例如 property !

最佳答案

Array 是构造函数。看prototype相反:

console.log(Reflect.ownKeys(Array.prototype));

结果:

["length", "constructor", "toString", "toLocaleString", "join", "pop", "push", "reverse", "shift", "unshift", "slice", "splice", "sort", "filter", "forEach", "some", "every", "map", "indexOf", "lastIndexOf", "reduce", "reduceRight", "copyWithin", "find", "findIndex", "fill", "includes", "entries", "keys", "concat", Symbol(Symbol.unscopables), Symbol(Symbol.iterator)]

关于javascript - 为什么我可以在 Array 属性对象中找到 Javascript Array forEach 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37257287/

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