This is the global function that runs on load:
$.fn.loadfns = function(specificfns) {
$('#wrapper').hide();
$('#load').fadeIn(400);
$(window).load( function() {
$('#load').fadeOut(400, function() {
$('#wrapper').fadeIn(600, function() {
specificfns;
})
})
});
};
Problem is, some pages require additional functions to be run after load (like inserting events into glDatePicker), so I’m trying to pass them as parameters for loadfns, like
$.fn.loadfns("alert('I won't be run');");
But nothing happens, it’s not executed. If I do
... rest of function ...
$('#wrapper').fadeIn(600, function() {
alert(specificfns);
})
It alerts “alert(‘I won’t be run’);” (without brackets) which should work as a function.
To pass a function around, you pass a function around, not a string.
If you want to allow just one extra function (which can, of course, call others):
Used like this:
If you want to allow multiple extra functions, pass in an array:
(Of course, if you’re in an ES5-enabled environment or using a shim, you might use
forEachinstead of theforloop.)Used like this:
You might consider putting
try/catchblocks around the calls to the functions if you want to handle exceptions from them.