In javascript, I have an object literal:
var objA = {
doStuff: function() {
// do objA stuff
}
}
I extend objA, and override the doStuff method:
var objB = _.extend(objA, {
doStuff: function() {
// do objB stuff
}
});
However, now when objB.doStuff() is called only objB stuff gets done.
I would like for both objA and objB stuff to be done. I tried the following:
var objB = _.extend(objA, {
doStuff: function() {
this.prototype.doStuff.call(this, arguments);
// do objB stuff
}
});
objB.__proto__ = objA;
However this doesn't work. I guess I don't understand how prototypal inheritance works when extending object literals. So, what is the right way to do this?