Ever forgot “alert()” when deployed to production
As developers we often forget to remove debug code on the client side such as “alert” calls , “debugger” statements and so on. So in order to avoid our team leader throw a chair at us here is a simple solution to this problem:
On the page startup ( page load or when ever you find it necessary) simply override the alert method like this:
Set alert to work only in debug
var originalAler = window.alert;
window.alert = function(message) {
if (Sys.Debug.isDebug) {
originalAler(message);
}
}
What i am doing here is to save the original alert method in a variable(delegate) and when someone uses the alert message simply check if we are in debug mode (I used ASP.NET Ajax) and call the original alert.
Enjoy.