js中arguments详解

 

 

 

 

1.当形参 数量不确定时,可以通过arguments对象获取传参的值。(为一个数组)

            function max(a) {
		     console.log(a);
		        var max = arguments[0];
		        console.log(arguments);//传入形参的值,数组形式。
		
		        for (val of arguments) {
		            if (val >= max) {
		                max = val;
		            }
		        }
		        return max;
		    }
		    var maxValue = max(1, 2, 4)
		    console.log(maxValue);  // 输出4

  

 

posted @ 2020-09-02 10:19  炽橙子  阅读(1052)  评论(0编辑  收藏  举报