0
 (function () {
        if (some scripts loaded) {
            otherFunction();
        } else {
            window.setTimeout( "CALL_SELF_AGAIN_HERE" , 100);
        }
    })();

How to call anonymous function from within anonymous function ?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

It's only "visible" inside that closure.
0

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();
})();

1 Comment

Accepted @James Allardice's answer as it was simpler, and respecting the scope as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.