Object.create() vs new SomeFunction() in javascript

Object.create builds an object that inherits directly from the one passed as its first argument.
With constructor functions, the newly created object inherits from the constructor's prototype, e.g.:
var o = new SomeConstructor();
In the above example, o inherits directly from SomeConstructor.prototype.
There's a difference here, with Object.create you can create an object that doesn't inherit from anything, Object.create(null);, on the other hand, if you set SomeConstructor.prototype = null;the newly created object will inherit from Object.prototype.
 
Very simply said, new X is Object.create(X.prototype) with additionally running the constructorfunction. (And giving the constructor the chance to return the actual object that should be the result of the expression instead of this.)
上一篇:两table水平滚动条级联滚动(同步滚动)。 table1放标题,table2放内容。


下一篇:创建Xml文件与修改Xml文件