quarta-feira, 3 de março de 2010

Alert redefinition

Hi guys!
Today a colleague of mine was blocked on a javascript error.
He has dynamic forms developed in c# with a lot of asp custom controls using also some javascript. So the page only showed him an alert message saying that an error ocurred!

His question was: How to determine in which place is giving me this error so i can correct it?

Interesting one...

Next i remebered the alert redefinition function that i documented a few posts below and made some adjustments to answer that question:


window.alert=function(native)
{
return function(e){
native(e);
window.status=arguments.callee.caller;
}
}(window.alert);

function nova()
{
alert('xpto');
}

So, now anywhere i have an alert, that alert will also inform me where that alert was fired. In this case printing that information to the status bar. This routine should only be used for "debugging" purposes, for obvious reasons. In this case, there was so much JS that writing this routine was faster than using JS Debugger and digging to the code.
Anyone has a better solution?

Sem comentários: