Constructor mode:
In constructor mode, by adding the new keyword in front of the constructor, it tells JavaScript to instantiate an object as if it were using a constructor, and the object member is defined by the function.
constructor, use this to refer to the newly created object.
There is a property named prototype in JavaScript, and when the JavaScript constructor is called to create an object, the new object will have all the properties of the constructor prototype.
To set properties:
1) use. 2) Use []
3) Use object.defineproperty
4) Use object.defineproperties
varNewObject = {};//var newObject = new Object ();Newobject.somekey= ' Hello world! ';varKey =newobject.somekey;newobject[' Somekey ' = ' Hello world!!! '; Object.defineproperty (NewObject,"Somekey", {value:' For more control of the property\ ' behavior ', writable:true, Enumerable:true, Configurable:true});varDefineprop =function(obj, key, value) {Config.value=value; Object.defineproperty (obj, key, config);}varperson = object.create (NULL);d Efineprop (person,' Car ', ' DeLorean ');d Efineprop (person,' dateOfBirth ', ' 1981 ');d Efineprop (person,' Hasbeard ',false); Object.defineproperties (NewObject, {"Somekey" : { "Value": "Hello World", writable:true }, "Anotherkey": {value:"Foo Bar", writable:false }});
Constructor JavaScript constructor mode.