【js语法】arguments

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>arguments</title>
</head>
<body>
<script>
    function inner(){
    	document.write(arguments.length);//传递进来的参数个数
    	console.log(arguments[0]);//索引从0开始的正整数
    }
    inner(10,5);

    function add(num1,num2){
    	arguments[0]=99; 
    	console.log(num1);
    }
    add(55,88);
</script>
</body>
</html>

如果声明了js严格模式,arguments通过下标参数无效。

非严格模式下:arguments通过下标的形式,可以修改传递进来的参数。

猜你喜欢

转载自blog.csdn.net/qq_39799094/article/details/109282338