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 goes wrong, or depending on some arbitrary logic.
A quick stub code, just for example (probably won’t do it like this, but just for an idea):
window.confirm = function(message, successCallback){
var ok = site.UI.confirmDialog(message);
if (ok && typeof(successCallback) == 'function'){
successCallback();
} else {
// maybe call original browser confirm?
// window.confirmOriginal...?
}
}
The question here is, how to get the original function if I’m overwriting it? Does it exist somewhere on the prototype, or am I looking at this all the wrong way?
Thanks.
Here’s a demo