In Javascript, the passed parameters can be modified within the function, as follows
function func1(name) {
name = 'lily';
alert(name);
}
func1('jack');//output lily
Look at another example
function fun1( n) {
this.name = n;
}
function fun2(name) {
fun1.call(this,'lily');
alert(name);
}
fun2("jack");//Output "jack"
The fun1 function wanted to change the parameter when calling fun2 to "lily", but it failed. What pops up is still "jack". Think about why?
In fact, fun1 still has the ability to modify the parameters when calling fun2, using the caller attribute
function fun1() {
arguments.callee.caller.arguments[0] = 'lily';
}
function fun2(name) {
fun1.call(this,name);
alert(name);
}
fun2("jack");//Output "lily"
Visible, outer layer The function is visible and modifiable to the call stack of the inner function.