本文介绍了检查函数在Javascript中需要多少个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 arguments.length
我可以看到有多少参数传递给函数。
With arguments.length
I can see how many arguments were passed into a function.
但是有吗一种确定函数可以使用多少个参数的方法,所以我知道应该传递多少个参数?
But is there a way to determine how many arguments a function can take so I know how many I should pass in?
推荐答案
Function.length
将完成这项工作(在我看来真的很奇怪)
Function.length
will do the job (really weird, in my opinion)
function test( a, b, c ){}
alert( test.length ); // 3
顺便说一句,这个长度属性非常有用,看看
By the way, this length property is quite useful, take a look at these slides of John Resig's tutorial on Javascript
这篇关于检查函数在Javascript中需要多少个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!