We allow users to write code which sometimes calls jQuery.ready(function(){..})
multiple times. It seems like the first function call that throws an error prevents execution of the rest of the functions.
There was a discussion about this here with the solution wrapped jQuery.ready()
in a delegate instead of wrapping the anonymous function parameter passed to jQuery.ready(..)
.
How can I override jQuery.ready(fn)
and wrap the passed-in function parameter in a delegate which wraps it in try/catch and the passes to jQuery.ready(delegate)
?
Here is an example:
<head>
<script>
// here is some code from third-party developer that sometimes throws an error
jQuery.ready(function() {
if ((new Date()).getMonth() == 0)
throw Error("It's January!");
});
</script>
</head>
<body>
<script>
// here is my code which should run regardless of the error in the <head> script
jQuery.ready(function() {
alert("I need to run even in January!");
});
</script>
</body>
What can I do to make code in run regardless of errors in ?