In JavaScript, we know that there are two common ways to create objects, one is to use the object's direct volume:
The object's direct quantity is a mapping table consisting of several value/key pairs, separated by a comma "," and the whole part is enclosed in curly braces "{}".
For example:
var empty={};
var people = {
name: ' Kobe ', age
: '% '
};
Another way is to create an object from new: Use a function call after new, which also becomes a constructor that initializes a new object by using new.
For example:
var arr = new Array ();
var date = new Date ();
var obj = new Object ();
In fact, JavaScript also defines a method in ECMAScript5 to create an object, Object.create (), and an argument can be an object.
For example:
var o = object.create ({x:1});
The prototype of the newly created object o is the parameter passed in Object.create (), and object o also has the attribute x.
Of course, can also create a common control object, similar to the effect of var o = {}, only need to change the parameters to Object.prototype, so that the creation of the object's prototype =object.prototype, in fact, is an instance of object.
var O1 = object.create (object.prototype);
var O2 = new Object;
var O3 = {};
As you can see from the figure above, these three methods create objects that are the same, that is, one of the most common object objects.
In addition, you can create a new object without a prototype by passing in the parameter null, which is not available in the first two ways.
var O4 = object.create (null);
The new object is pathetic, he doesn't have any prototypes, which means it doesn't have a built-in method, no ToString (), valueof, etc.