我使用函数Reflect.ownKeys(Array)处理ECMAScript 6。我得到的属性是:
console.log(Reflect.ownKeys(Array))
["length", "name", "arguments", "caller", "prototype", "isArray", "from", "of", Symbol(Symbol.species)]
但我仍然可以在阵列上使用 forEach 方法!但我无法找到定义函数forEach的位置,例如属性!
答案 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)]