In Javascript scripts, the reference principle of parameters: the internal parts of the referenced parameters (such as attributes) can be modified, but the reference corresponding to the parameter cannot be modified.
A test example is as follows:
< ;script language="javascript">
//dosomething1, for references, 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(a.a);
}
//dosomething2
function dosomething2(v){
v.a = v.a '!!!'; //Modify the reference variable Attribute, modified successfully
v = 'try'; //Trying to modify variable reference, modification failed
}
//Test 2
function test2(a){
var a = {a :'test',b:'is',c:'ok'};
dosomething2(a);
alert(a.a);
}
test2();
< /script>
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn