JavaScript can modify the parameters passed in the function, as follows
Copy Code code as follows:
function Func1 (name) {
name = ' Lily ';
alert (name);
}
Func1 (' Jack ');/output Lily
Look at one more example
Copy Code code as follows:
function fun1 (n) {
THIS.name = n;
}
function fun2 (name) {
Fun1.call (this, ' Lily ');
alert (name);
}
Fun2 ("Jack");/output "Jack"
The FUN1 function tried to change the parameters of the fun2 call to "Lily", but it did not succeed. The pop-up is still "Jack." Think about why?
In fact, FUN1 still has the ability to modify the parameters of the FUN2 call, using the caller attribute
Copy Code code as follows:
function Fun1 () {
Arguments.callee.caller.arguments[0] = ' lily ';
}
function fun2 (name) {
Fun1.call (This,name);
alert (name);
}
Fun2 ("Jack");/output "Lily"
Visible, the outer function is visible to the call stack of the inner function and can be modified.