In JavaScript, all other values are objects except number, string, Boolean, NULL, and undefined. objects can be declared directly by literal amounts, or they can be created by using the new operator. Unlike the Java language, the property in a JavaScript object can be added or deleted dynamically, and the property in the object can also be an empty string:
Copy Code code as follows:
Properties in object can be added/deleted dynamically
var o = {x:1, y:2};
Console.log (o);//object {x=1, y=2}
Delete o.y;
O.z = 3;
Console.log (o);//object {x=1, z=3}
Empty string is allowed as Object
var O2 = {"": the, "P": 99};
Console.log (O2);//object {=88, p=99}
For constructor function, the "new" Operation returns an object.
function Computer (x, y) {
this.x = x;
This.y = y;
}
var c = new Computer (126, 163);
Console.log (c);//computer {x=126, y=163}
var C2 = new Computer (126);//missing parameter value would be "undefined"
Console.log (C2);//computer {x=126, y=undefined}
C.z = 66;
Console.log (c);//computer {x=126, y=163, z=66}
Delete c.y;
Console.log (c);//computer {x=126, z=66}
If you use the new operator to create a new object, the role function is not a constructor of a class, but just a normal function, then JavaScript will return an empty object after executing the function:
Copy Code code as follows:
For pure function, "new" Operation returns a empty object.
function compute (x) {
Console.log ("Execute function compute");
return x*2;
}
var a = new compute ();
Console.log (a);//compute {}
object property
The object in JavaScript has the following 3 properties:
1.prototype. A reference that points to the prototype object. The property in the prototype object can be inherited by object.
2.class. A string that represents the class name of object.
3.extensible. Boolean value that indicates whether the property is allowed to be added dynamically in object. This property is valid only in ECMAScript 5.
Property Properties
The property in object also has 3 properties:
1.writable. Whether the property is writable.
2.enumerable. Whether the property is enumerated when the For/in statement is used.
3.configurable. Whether the property's properties can be modified and whether it can be deleted.