考虑:
> function hello(what) {
. what = "world";
. return "Hello, " + arguments[0] + "!";
. }
> hello("shazow")
"Hello, world!"
为什么改变价值 what
改变的价值 arguments[0]
?
考虑:
> function hello(what) {
. what = "world";
. return "Hello, " + arguments[0] + "!";
. }
> hello("shazow")
"Hello, world!"
为什么改变价值 what
改变的价值 arguments[0]
?
“为什么改变价值
what
改变的价值arguments[0]
?”
因为这就是它的设计工作方式。形式参数直接映射到arguments对象的索引。
那是 除非 你在 严格的模式,您的环境支持它。然后更新一个不会影响另一个。
function hello(what) {
"use strict"; // <-- run the code in strict mode
what = "world";
return "Hello, " + arguments[0] + "!";
}
hello("shazow"); // "Hello, shazow!"
“为什么改变价值
what
改变的价值arguments[0]
?”
因为这就是它的设计工作方式。形式参数直接映射到arguments对象的索引。
那是 除非 你在 严格的模式,您的环境支持它。然后更新一个不会影响另一个。
function hello(what) {
"use strict"; // <-- run the code in strict mode
what = "world";
return "Hello, " + arguments[0] + "!";
}
hello("shazow"); // "Hello, shazow!"