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:
var origConfirm = window.confirm; //store for future use
window.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?"