我一直在这里摆弄一些代码。由于某种原因,一个函数被检测为抽象数组,因为它具有length属性。不是主要问题,bc为0,但我发现这个怪异的现象。
var test_set = [null,
undefined,
NaN,
true,
false,
1,
'a',
{test:'test'},
[0],
function(){},
/test/
];
var index,
key,
test;
function isArrayAbstract (obj) {
return (obj != null) && (obj.length === +obj.length);
};
for(index = 0; index < test_set.length; index++){
test = isArrayAbstract(test_set[index]);
console.log('Mark | ' + test_set[index]);
console.log(test);
}
length是函数对象的属性,它指示函数期望多少个参数,即形式参数的数量。相比之下,arguments.length对于函数而言是本地的,并提供了实际传递给该函数的参数数量。
参见示例:
console.log( (function () {}).length ); /* 0 */
console.log( (function (a) {}).length ); /* 1 */
console.log( (function (a, b) {}).length ); /* 2 etc. */
console.log( (function (...args) {}).length ); /* 0, rest parameter is not counted */
也请参考ECMAScript语言规范:
此子句中描述的每个内置Function对象(无论是构造函数,普通函数还是两者)都具有length属性,其值是整数。除非另有说明,否则该值等于函数说明的子标题中显示的最大命名参数数量,包括可选参数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句