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

后端 未结 11 2503
失恋的感觉
失恋的感觉 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:01

    Internally Object.create does this:

    Object.create = function (o) {
        function F() {}
        F.prototype = o;
        return new F();
    };
    

    The syntax just takes away the illusion that JavaScript uses Classical Inheritance.

提交回复
热议问题