Hanshunping JavaScript Instructional Video _ Learn notes 13_ Class and object Details _ Create objects in several ways _js object Memory Analysis __js

Source: Internet
Author: User
Tags garbage collection ming
Object--function Special DescriptionIn JS, everything is an object.
Class (Prototype object) is actually an object, it is actually an instance of the function class, through which we can create our own object instances, which can be explained by the following code
function person () {  
}  
var a=new person ();  
Window.alert (Person.constructor);
Object Instance--how to create an object instance var object name =new class name/prototype object name ();
Object Instance--How to access (use) a member variable of an object instance object instance name. property name;
object instance name [' Property name '];

The way an object instance name ["Variable name"] can be used to implement dynamic access variables, such as:
function person () {  
}  
var p1=new person ();  
P1.name= "Shunping";  
Supplementary Note: with Var and without var difference Look at the code:

 

the meaning of dynamic access variables:Can be used as a string to splice access specific look at the following code

 
 Deepen Understanding To make the impression, we define a human (person) (including name, age)

Look at the following code

 

From the above code can be known, JS Object Transfer is also a reference to pass

var a=new person (); The new person () is a real data, and a is a reference to it
Deep Understanding:

When will the contents of the heap be recycled?
Object Recycling Mechanism (GC), garbage collection (GC) is how to determine the contents of the heap is garbage, memory by JS engine management, JS engine is a part of the browser,JS engine maintenance of a table



Garbage collection mechanism is a passive recovery method, when the GC to call, we are not aware of, anyway not always in the call of
In JS there is also a proactive way to remove the memory, the active release of RAM: delete Delete can only delete the properties of an object, you can not directly delete an object as follows:

Delete a.age;  Delete the age attribute directly, even if B is not empty, b.age can not access it.
delete A;  That's not true.

Delete Deletes an object's properties directly
Delete Object name. property//This will immediately release this property space of the object

Look at one more code:
var a=new person ();
a.age=10;
A.name= "Xiao Ming";
var b=a;
document.write (B.name); Output Xiao Ming
b.age=200;
document.write (A.age); Output 200

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.