Home > Web Front-end > JS Tutorial > body text

Introduction to citation examples in Javascript_Basic knowledge

WBOY
Release: 2016-05-16 16:58:47
Original
1040 people have browsed it

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:

Copy code The code 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>
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template