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