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

后端 未结 11 2682
失恋的感觉
失恋的感觉 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 05:39

    Accordingly to this answer and to this video new keyword does next things:

    1. Creates new object.

    2. Links new object to constructor function (prototype).

    3. Makes this variable point to the new object.

    4. Executes constructor function using the new object and implicit perform return this;

    5. Assigns constructor function name to new object's property constructor.

    Object.create performs only 1st and 2nd steps!!!

提交回复
热议问题