我无法理解这段javascript代码,请任何人帮助我理解这一点。
var some = []['forEach']['constructor'];
答案 0 :(得分:1)
与[].forEach.constructor
相同,与Array.prototype.forEach.constructor
基本相同。
答案 1 :(得分:0)
以下是如何分解它:
[]['forEach']['constructor'];
// Convert bracket property access notation to dot notation
[].forEach.constructor;
// `forEach` is a property of Array.prototype
Array.prototype.forEach.constructor;
// `forEach` is a function reference with a
// `constructor` property, due to `Function.prototype`
Function.prototype.constructor;
// `Constructor.prototype.constructor === Constructor`, generally
Function;
console.log(
[]['forEach']['constructor'] === Function //=> true
);
如果您问为什么这段代码会有用,我不太确定。可能是混淆。