I have a JavaScript file, Mybasefile.js, which has the function Mybasefunction(). I want to override this function in another JavaScript file. When the function is called in a button click, I want the original Mybasefunction() to be executed along with some other code. How can I do this?
Add a comment
|
1 Answer
place this code in the override file. Make sure the override file is included after the orginal one.
var orig_Mybasefunction = window.Mybasefunction;
window.Mybasefunction = function(){
orig_Mybasefunction();
...
}
3 Comments
Martijn
You might want to hide the
orig_Mybasefunction variable by wrapping this code in an anonymous function: (function () { var orig_ ... }()); That way, you won't clobber the global namespace, and you'll be able to use the name orig_Mybasefunction elsewhere without disturbing this code.Horia Dragomir
I know, I know -- but let's get the basics down first.