As you might know new
and Object.create
do a hidden action than we can call setPrototype
.
Object.create = function(proto, properties) {
var obj = {};
setPrototype(obj, proto);
Object.defineProperties(obj, properties);
return obj;
}
function fakeNew(Constructor) {
var obj = {};
setPrototype(obj, Constructor.prototype);
Constructor.call(obj);
return obj;
}
It's not than "new is inside Object.create" or "Object.create is inside new". Both does the prototype assignation and other actions.
Actually there is a way to implement setPrototype
but surely you know it's not standard.
function setPrototype(obj, proto) {
obj.__proto__ = proto;
}