What is difference between creating object using Object.create() and Object.assign()?

Let’s compare obj1 and obj2 in this code: var target1 = {}, target2 = {}; var obj1 = Object.create(target1, {myProp: {value: 1}}); var obj2 = Object.assign(target2, {myProp: 1}); Prototypical chain Object.create creates a new object with the specified [[Prototype]], and Object.assign assigns the properties directly on the specified object: obj1 !== target1; obj2 === target2; … 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)