Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript:为什么更改参数变量会更改“arguments”;数组";?_Javascript - Fatal编程技术网

JavaScript:为什么更改参数变量会更改“arguments”;数组";?

JavaScript:为什么更改参数变量会更改“arguments”;数组";?,javascript,Javascript,考虑: > function hello(what) { . what = "world"; . return "Hello, " + arguments[0] + "!"; . } > hello("shazow") "Hello, world!" 为什么更改的值会更改参数[0]的值 “为什么更改what的值会更改参数[0]的值?” 因为它就是这样设计的。形式参数直接映射到arguments对象的索引 除非您处于严格模式,并且您的环境支持严格模式。那么更新一个不会

考虑:

> function hello(what) {
.     what = "world";
.     return "Hello, " + arguments[0] + "!";
. }
> hello("shazow")
"Hello, world!"
为什么更改
的值会更改
参数[0]
的值

“为什么更改
what
的值会更改
参数[0]
的值?”

因为它就是这样设计的。形式参数直接映射到arguments对象的索引

除非您处于严格模式,并且您的环境支持严格模式。那么更新一个不会影响另一个

function hello(what) {
    "use strict"; // <-- run the code in strict mode
    what = "world";
    return "Hello, " + arguments[0] + "!";
}
hello("shazow"); // "Hello, shazow!"
函数hello(什么){

“使用strict”;//哦……在这种情况下:为什么设计成这样?这种设计在任何地方都有记录吗?(当然不是说我不相信你,我只是想了解更多细节)哦,等等,我们开始:“注1”@DavidWolever的10.6参数对象中:语言是ECMAScript规范中的文档。ECMAScript 5中引入了严格模式。@DavidWolever为方便起见,在github上有一个。阅读量比官方规范轻一些: