In JavaScript, we know that there are two common ways to create objects, one is to use the direct amount of objects:
The direct amount of an object is a mapping table consisting of several value/key pairs separated by a comma "," and the entire section enclosed in curly braces "{}".
For example:
var empty={}; var = { name:' Kobe ', age :' People ' };
Another way is to create an object with new: A function call is used after new, and the function is also a constructor that initializes a new object with a.
For example:
var New Array (); var New Date (); var New Object ();
In fact, JavaScript also defines a method in ECMAScript5 to create an object,object.create (), and the argument can be an object .
For example:
var o = object.create ({x:1});
Then the prototype of the newly created object o is the parameter passed in Object.create (), and the object o also has the attribute x.
Of course, you can also create a normal object, similar to the effect of var o = {}, only need to change the parameter to Object.prototype, let create object prototype =object.prototype, in fact, is an instance of object.
1 var o1 = object.create (object.prototype); 2 var New Object; 3 var o3 = {};
As you can see, these three methods create objects that are the same, that is, one of the most common object objects.
In addition, it is possible to create a new object without a prototype by passing in the parameter null , which is not available in the first two methods.
var o4 = object.create (null);
This new object is pathetic, he does not have any prototype, that is, it does not have a method built into the object, not ToString (), valueof and so on.
"Reprint" http://blog.csdn.net/hutaoer06051/article/details/7983316
javascript: Creating Objects with the Object.create () method