Sunday, March 11, 2012

debug assert in js

Just like in .NET...

debug.assert(<boolean expression>);

The assert will result in an alert if the expression evaluates to false. And you'll have the option to break into the debugger (assuming you've got script debugging enabled in IE). In Firefox, you'll want to set the script debugger to break on exceptions to cause the break to have an effect.


Actually there is more:

debug.assert(expr, message, showCaller)

You can show a message as well, as it helps identifying the problem better. If you have some general-purpose function, it might help to see the particular caller, and so you can pass true for showCaller to get that information as well.

No comments:

Post a Comment