0

On about line 18, make the anonymous function with the code 'window.didExecute = true' execute.

  var anonymousFunction = function(){};

  (function(){window.didExecute=true;})

doesn't work, why?

1
  • You need to add () after your function. ((function(){window.didExecute=true;})()). Or remove the ( ) around it. Commented Nov 11, 2013 at 13:08

1 Answer 1

1

Because the function is never executed. Use an immediately invoked function expression:

(function(){window.didExecute=true;})();

The () at the end is what actually makes it a function call, resulting in the body of the function executing.

If you weren't using anonymous functions, your code would be the same as doing:

function foo() {
    window.didExecute = true;
}

Then never calling foo().

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

Comments

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.