Is this even possible?
function foo() {
// do stuff
}
foo.prototype = {
// stuff...
bar: function() {
// do some things with this, where this refers to foo
},
bar.prototype: {
// set some definitions for bar to work with.
// Where does "this" go and what does it refer to?
}
}
No. You’d need to use
Although this won’t work. There is no reason to put the
barconstructor onfoos prototype, because when instantiating bar objects by usingnew ((new foo()).bar)(), there will be no reference to the foo instance. You could equally usenew foo.prototype.bar().