Tag: It's called ASC initialization operator ext Process Object-oriented what
Description (2017-4-2-21:50:45)
What is the function of the constructor:
1. Initialize the data.
2. To add attributes to the object in JS, initialize the attribute value with.
Second, the process of creating objects:
1. Code: var p = new person ();
2. First operator new creates an object that resembles {} and is a "no member" object.
* Use new to create an object whose type is the name of the constructor that created it (for example, person type).
* Use {} Anyway is the object type, which is equivalent to "new object ()".
3. Then call the constructor to initialize the member.
* constructor at the beginning of the call, there is an assignment operation, the object that this= just created.
* Therefore in the constructor, this represents the object that was just created.
4. In the constructor, add members to the object using the object's dynamic properties.
Third, analyze the code, write out the implementation process of each step:
Break point in line 2nd, but execution starts directly from line 7th, because 7 rows are assignments, and 2 lines are just function declarations. Run-by-statement, you can see in watch that this is slowly increasing the property, and finally P has three properties.
1 <script type= "Text/javascript" >2 function person (name, age, gender) { 3this . name = name; 4 this. Age = Age ; 5 this. gender = gender; 6 }7 varnew person ("Zhang San", 19, "male"); 8 </script>
JavaScript Advanced Object-oriented (13)--Constructor execution procedure