I have this code
function test(){};
test.prototype.testMethod = function(){return 1;}
var t = new test();
t.testMethod();
now I need to override the method testMethod so that I can still call the base method in the override.
How can I do that using prototype ?
If you need to overwrite the base method for an individual instance, you can still refer to the one defined in the prototype:
Try it: http://jsfiddle.net/aeBWS/
If you want to replace the prototype method itself, you have a couple of routes. The most simple one is to just chose a different name for your function. If that isn’t possible, then you could copy the old method to one with a new name (like
_testMethod) and call it that way:Try it: http://jsfiddle.net/x4txH/