Understanding Crockford’s Object.create shim

if (typeof Object.create !== ‘function’) { Object.create = function (o) { function F() {} F.prototype = o; return new F(); }; } var oldObject={prop:’Property_one’ }; // An object var newObject = Object.create(oldObject); // Another object In the above example we’ve created a new object newObject using create method which is a member function of Object … Read more

JavaScript inheritance: Object.create vs new

In your question you have mentioned that Both examples seem to do the same thing, It’s not true at all, because Your first example function SomeBaseClass(){…} SomeBaseClass.prototype = { doThis : function(){…}, doThat : function(){…} } function MyClass(){…} MyClass.prototype = Object.create(SomeBaseClass.prototype); In this example, you are just inheriting SomeBaseClass’ prototype but what if you have … Read more

Using “Object.create” instead of “new”

With only one level of inheritance, your example may not let you see the real benefits of Object.create. This methods allows you to easily implement differential inheritance, where objects can directly inherit from other objects. On your userB example, I don’t think that your init method should be public or even exist, if you call … Read more

Understanding the difference between Object.create() and new SomeFunction()

Very simply said, new X is Object.create(X.prototype) with additionally running the constructor function. (And giving the constructor the chance to return the actual object that should be the result of the expression instead of this.) That’s it. 🙂 The rest of the answers are just confusing, because apparently nobody else reads the definition of new … Read more