How does enclosing a Javascript function invocation in parentheses affect the semantics?
-
Why is (function(){...}()); equivalent to (function(){...})(); when function(){...}(); is an error? Looking at the "railway diagrams" in "The Good Parts", even the last of these appears valid: a statement can be an expression; an expression can be an expression followed by an invocation; an expression can be a literal; the last line is a function literal followed by an invocation. Yet there is clearly something in the language definition that says otherwise. This is a follow-up to (this is what I thought that Q was asking, hence my dumb, now deleted comment).
-
Answer:
wrote a very thorough article regarding Immediate Invoked Functions Expressions, which can be found here: http://benalman.com/news/2010/11/immediately-invoked-function-expression/
Rick Waldron at Quora Visit the source
Related Q & A:
- How to access a nested function from another nested function in javascript?Best solution by devarticles.com
- How to pass a javascript object back to the server?Best solution by developer.mozilla.org
- how to call a function in Python in another function?Best solution by Yahoo! Answers
- How to call Javascript function in PHP?Best solution by Stack Overflow
- How to graph a quadratic function on a graphing calculator?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.