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

后端 未结 11 2487
失恋的感觉
失恋的感觉 2020-11-22 05:05

I recently stumbled upon the Object.create() method in JavaScript, and am trying to deduce how it is different from creating a new instance of an object with

11条回答
  •  情歌与酒
    2020-11-22 06:04

    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 either. ;)

提交回复
热议问题