Hi there,

it might sound silly but out of curiosity I just created a test case for this one using a snippet of code to test both declarations performance. There seems to be no difference in that respect, have a look: http://jsperf.com/testing-parens

Fran

On 15/02/11 09:12, Peter van der Zee wrote:
On Tue, Feb 15, 2011 at 9:53 AM, Ivan S <[email protected] <mailto:[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]
    <mailto:jsmentors%[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]

--
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