能否从外部作用域获取函数参数数量?
var foo = function(a,b,c) {
}
alert(foo.arguments.length); // how to do it? possible?
能否从外部作用域获取函数参数数量?
var foo = function(a,b,c) {
}
alert(foo.arguments.length); // how to do it? possible?
Function.length
:function test(a, b, c) {
// code
}
console.log(test.length); // 3
顺便提一下,函数期望的参数数量被称为arity。曾经有一个名为Function.arity
的方法,但已被弃用,推荐使用Function.length
。
移除foo.arguments.length
中的参数。
foo.length
foo.length
。它提供了函数定义中定义的参数数量。