Javascript Function With Prototype Within Parent Function Prototype
Is this even possible? function foo() { // do stuff } foo.prototype = { // stuff... bar: function() { // do some things with this, where this refers to foo
Solution 1:
No. You'd need to use
functionbar() {...}
bar.prototype = {...};
functionfoo() {...}
foo.prototype.bar = bar;
Although this won't work. There is no reason to put the bar
constructor on foo
s prototype, because when instantiating bar objects by using new ((new foo()).bar)()
, there will be no reference to the foo instance. You could equally use new foo.prototype.bar()
.
Post a Comment for "Javascript Function With Prototype Within Parent Function Prototype"