Reputation: 1472
Premise: I'm try to abbandon constructor pattern
As you can see in looking at console.log()
here
//Constructor pattern
function F(){}
F.prototype.foo = null;
console.log(new F());
//Object create pattern
var FPrototype = {};
FPrototype.foo = null;
console.log(Object.create(FPrototype))
the object created by Object.create
API has the __proto__
properties referencing the prototype as Object
while the one created by constructor has the __proto__
prop referencing the prototype as the name of the constructor function.
I suppose that this behaviour is trying to simulate the strong typed langs, assuming that your constructor defines a new type identified by the constructor name itself.
That said, when my prototype chain grows I find very useful to identify different prototypes by name/"type", so is there any way to correctly have this using Object.create
instead of constructor?
Upvotes: 0
Views: 37