答案 0 :(得分:4)
b.push
是一个函数,但函数只是另一种值 - []
运算符可以尝试访问任何类型的值的属性。但是,如果找不到该属性,结果将是undefined
,这就是这里的情况;函数通常没有0
属性。
var b = [];
var someFunction = b.push;
console.log('0' in someFunction); // false; function doesn’t have a 0 property
console.log(someFunction[0]); // undefined for the same reason
console.log('length' in someFunction); // true; functions have a length property!
console.log(someFunction['length']); // 1; just like someFunction.length