js的内建arguments数组

调用函数时,只需在函数名后加一对用于传递参数的括号即可。var result = sum(1,2)

如果调用参数(a,b)的时候没有给值,则值默认为undefined。即使传递参数过多,多余的部分也会被默默忽略。

而每个函数都有一个内建的arguments数组,他能返回函数所接受的所有参数。例如

js代码:

 function test1(){
        $.each(arguments,function(index,val){
            console.log(index+":"+val);
        });
    }

调用jsp代码:

<button type="button" id="btn_select_all_area" onclick="test1('a','b','c','d','e','f')">

运行结果:

原文地址:https://www.cnblogs.com/hy928302776/p/6946524.html