Consider following code:
mynamespace.myclass = function() {
this.myfunction = function() { alert("Original"); }
}
What I’m trying to do is to overwrite myfunction from outside of mynamespace.myclass declaration.
While adding new functions through prototype seems to work ok, if I define a function with the same name the original function doesn’t get overwritten:
mynamespace.myclass.prototype.myfunction = function() {
alert("Overwritten");
}
Any ideas?
That’s because
myfunctionis being added in the constructor, which happens after the prototype properties are added (so that the “Original” is in fact overwriting the “Overwritten”).You’ll have to mimic this behaviour, by overwriting
mynamespace.myclassitself: