In Javascript scripts, the reference principle of parameters: the referenced parameters can be modified internally (such as properties), but the reference corresponding to the parameters cannot be modified.
An example of a test is as follows:
The code copy is as follows:
<script language="javascript">
//dosomething1, For reference, the variable itself cannot be modified, but the internal structure of the variable can be modified
function dosomething1(a){
a = 'try';
}
//Test 1
function test1(){
var a = {a:'test',b:'is',c:'ok'};
dosomething1(a);
alert(aa);
}
//dosomething2
function dosomething2(v){
va = va + '!!!'; //Modify the attribute of the reference variable, the modification is successful
v = 'try'; //Try to modify the variable reference, but the modification failed
}
//Test 2
function test2(a){
var a = {a:'test',b:'is',c:'ok'};
dosomething2(a);
alert(aa);
}
test2();
</script>