Reputation: 405
I'm working on a big project and decided against prototyping for inheritance (I wanted more control over var
and this.*
access).
Anyways, I have classes that look like this:
FirstScene.prototyp
FirstScene.prototype = Object.create(_SceneCanvas.prototype)
FirstScene.prototype.constructor = FirstScene
function FirstScene(){
var arguments = [/*args*/]
_SceneCanvas.apply(this, arguments)
this.bar = function(){ /*do other stuff*/ }
}
If I was in foo()
or bar()
and wanted to call the parent method, how would I go about doing that? I tried some code that looked like _SceneCanvas.prototype.foo.call(params)
to no avail.
Thanks!
Upvotes: 0
Views: 36
Reputation: 1152
In JavaScript the common practice is to get a reference to the old function and call it from within the new function.
var bar = this.bar;
this.bar = function () {
bar.call(this);
// ...
};
Please check out this fiddle to see it in action.
Upvotes: 3