Skip to content Skip to sidebar Skip to footer

How To Override Global Functions In Javascript, But Keep A Reference To The Original Function?

I'd like to implement a custom function for window.confirm, so I don't have to rewrite a large amount of legacy code, but be able to fallback to the original function if something

Solution 1:

Here's a demo

var origConfirm = window.confirm; //store for future usewindow.confirm = function(msg){   //override
     alert(msg);   
}

window.confirm('override!');      //should now be an alert
origConfirm('old confirm');       //the old confirm

Post a Comment for "How To Override Global Functions In Javascript, But Keep A Reference To The Original Function?"