Jishnu A P
Jishnu A P

Reputation: 14382

How to override a function in another javascript file?

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?

Upvotes: 9

Views: 23526

Answers (1)

Horia Dragomir
Horia Dragomir

Reputation: 2888

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();
    ...
}

Upvotes: 21

Related Questions