(function () {
if (some scripts loaded) {
otherFunction();
} else {
window.setTimeout( "CALL_SELF_AGAIN_HERE" , 100);
}
})();
How to call anonymous function from within anonymous function ?
Give it an identifier:
(function named () {
if (some scripts loaded) {
otherFunction();
} else {
window.setTimeout( named , 100);
}
})();
This is what's known as a "named function expression". The identifier is only in scope inside the function it refers to.
Don't use arguments.callee since it's deprecated and will actually throw a syntax error in strict mode.
If you want to avoid creating any new top level function names, you can put your code in a local function that gives you a function name to both execute initially and to pass to setTimeout():
(function () {
function doit() {
if (some scripts loaded) {
otherFunction();
} else {
window.setTimeout(doit, 100);
}
}
// execute the first time
doit();
})();