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

时间:2016-05-16 15:13:40

标签: javascript arrays

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

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

但我仍然可以在阵列上使用 forEach 方法!但我无法找到定义函数forEach的位置,例如属性!

1 个答案:

答案 0 :(得分:5)

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)]