syntax - Location of parenthesis for auto-executing anonymous JavaScript functions? -


I was recently comparing the version in my project and saw the difference in the expression of the function. Created and self executed.

  (function () {// code here}) ();   

But now it wraps automatically execute the function into brackets.

  (function () {// code here} ());   

The accepted answer to the comment by CMS is both: (function () {}) (); and (function () {} ()); is valid. ??? ???

I was wondering what is the difference? Has the former taken a global, anonymous function except memory? Where should the bracket be located?

They are virtually identical.

First creates brackets near a function so that it is a valid expression and it is invited. The outcome of the expression is undefined.

Performs another function and automatically creates brackets around the invitation, it creates a valid expression, it also evaluates to undefined.

I do not think there is a "right" way of doing this, because the result of expression is the same. & gt; () () () () () () () () () () Foo '} ()) "foo"

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -