On Tue, Feb 15, 2011 at 9:53 AM, Ivan S <[email protected]> wrote:

> Hi all.
>
> I don't know ECMA script specification so well, so if someone can explain
> what's the difference between this two:
>
>
> (function() {
>
> }());
>
>
> (function() {
>
> })();
>
>
> (brackets have different positioning)
>
>
> Intuitively, I can understand the difference, but I would like technical
> explanation.
>

The parenthesis are actually a "grouping operator" in js. In practice this
means that you can change the order of precedence for operators using
parens, `5+(7*9)` vs `(5+7)*8`. We do it all the time, most of the time
without even thinking about it.

Specification-wise, the grouping operator combined with the comma operator
can have some minor effects, especially with eval and other edge cases. This
is due to the (specification) internal notion of a Reference. I'm sure
somebody will jump on this ship to explain that in detail if you're
interested ;)

As for the given example, there is absolutely no difference, a function is
created first and executed right after doing so. There are no observable
differences. Internally, the difference is whether the grouping operator
returns a function or the result of calling that function.

- peter



>
>
> Thank you very much.
>
>
>
> Ivan
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to