JS Object-oriented

Source: Internet
Author: User

Object needs to be aware of the place;

When you create an object: 1.

varobj =New Object(); Obj.name="Tom"; Obj.age=" -";/* This is a reference to the created object; */
obj["var"] = "123" ;//This is also A method of writing a parameter to an object;
console.log (obj["var"]) ;//access is required at the same time;
obj["123"] = 789;
var n = "123";  
Console.log ([n]);//"789";
Obj.test1 = null;
 
Obj.test2 = undefined; Console.log (OBJ.TEST2) prints out a undefined;
Obj.test3 = true; The same truth will print true;
Console.log (obj.test1);//null a null output in Console.log printing will not error;
The data type of JS can be any data type, or even it can be an object such as:

   Obj.test =obj2; var obj2 = {name: "Pig"}; Console.log (obj.test); Print out name = "Pig"
 /* in operator
*-This operator allows you to check whether an object contains a specified property
* Returns True if any, no returns false;
*-Syntax:
* "Property name" in Object
*/
Console.log ("Test" in obj);
var obj2=//This is also a way to create objects;
{
Name: "Xiaobai",
"Age": "23"//The attribute name in the object is quoted; but I don't recommend it.
};
var obj3 =
{
Name: "Ton",
Age: "18"
}
var obj4 = obj3;
Console.log (Obj4.name); Print out "ton".
If I change obj3.name = "Lily";
Console.log (Obj4.name); Print out "Lily".
So I now change obj4 = null;
Console.log (Obj3.name); Print out "Lily"
Note: Here obj3 is created in the heap of objects, it just get a heap stored in the address such as 0x123, the same obj4 is copied obj3 address to manipulate.
if I create 2 obj such as:
var obj5 =
{
name: "Ton",
Age : "+"
};
var obj6=
{
name: "Ton",
Age : "+"
}
Obj5 = = obj6;
then I change
obj5.name = "Tom";
Console.log (obj6.name);//Print out "ton".
Note: Although they are all the same here, each created object is created in the heap and is a different block, so obj6 does not change when the obj5 changes.

The actual development must pay attention to.

JS Object-oriented

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.