It's been advised that Derived.prototype = Object.create(Base.prototype);
is preferable to Derived.prototype = new Base();
(like in this SO answer).
That makes sense, but when I use this approach, like so:
function B(){};
B.prototype.doA = function(){};
function D(){};
D.prototype = Object.create(B.prototype);
var d = new D();
console.log(Object.getPrototypeOf(d));
it outputs Object {doA: function}
to the console, and logging console.log(d)
shows an object with __proto__: Object
. Why is it not D {doA: function}
?
Everything else seem to work:
d.doA();
d instanceOf D; // true
d instanceOf B; // true
It seems weird. Am I doing something wrong?