This article provides a detailed analysis of the Javascript dynamic method call and Parameter Modification issues. If you need a friend, refer to it, we hope to help you in Javascript to modify the passed parameters in the function, as shown below:
The Code is as follows:
Function func1 (name ){
Name = 'lily ';
Alert (name );
}
Func1 ('jack'); // output lily
Let's look at another example.
The Code is as follows:
Function fun1 (n ){
This. name = n;
}
Function fun2 (name ){
Fun1.call (this, 'lily ');
Alert (name );
}
Fun2 ("jack"); // output "jack"
The fun1 function wants to change the parameter used for fun2 calling to "lily", but it fails. The pop-up is still "jack ". Think about why?
In fact, fun1 still has the ability to modify the parameters used for fun2 calling, and uses the caller attribute
The Code is as follows:
Function fun1 (){
Arguments. callee. caller. arguments [0] = 'lily ';
}
Function fun2 (name ){
Fun1.call (this, name );
Alert (name );
}
Fun2 ("jack"); // output "lily"
It can be seen that the outer function is visible to the call stack of the inner function and can be modified.