There's a significant difference. In order to dispel the confusion when talking about the "prototype" property of a Function, and an object's prototype that is used for inheritance, I'll call object prototypes [[Prototype]]
.
Note that setting the property "prototype" of a Function - MyConstructor.prototype = SomeObject
determines what an object's [[Prototype]]
will be when created via new Function
:
MyObj = new Constructor();
MyObj's [[Prototype]]
is Constructor.prototype
Now for your code:
PrototypeObj = Object.create(MySuperConstructor.prototype);
MyConstructor.prototype = PrototypeObj;
MyObj = new MyConstructor();
Here's the [[Prototype]]
chain for MyObj
:
MyObj -> PrototypeObj -> MySuperConstructor.prototype(the object with myMethod) -> ...
If instead you use the second snippet:
MyConstructor.prototype = MySuperConstructor;
MyObj = new MyConstructor();
Here's the [[Prototype]]
chain for MyObj
:
MyObj -> MySuperConstructor -> MySuperConstructor's [[Prototype]] (which happens to be Function.prototype) -> ...
In the second case, the object you defined and set to MySuperConstructor.prototype is not in MyObj's prototype chain at all.