On Jan 15, 2011, at 2:49 PM, Diego Perini wrote:

> <[email protected]> wrote:
>> #1 - function(){ WScript.Echo("foo") }();
>> #2 - (function(){ WScript.Echo("foo") }());
>> #3 - (function(){ WScript.Echo("foo") })();
>> 
>> #1 is an error. #2 and #3 both work.
>> 
>> If I type "foo" or if I type ("foo") they are semantically the same
>> thing. same as if I type 1 vs (1), etc.
>> The fact that "function(){}()" and "( function(){}() )"  are not
>> semantically the same seems a bit backwards logically.
>> 
>> Hence I prefer style #3
>> 
> 
> I prefer style #3 too, mostly because I believe the components (FD and
> Expression) are better grouped and separated.



Diego,

Thanks for adding the clarity between the grouping and expression. 



On Jan 15, 2011, at 2:27 PM, Michael Haufe (TNO) wrote:

> #1 - function(){ WScript.Echo("foo") }();
> #2 - (function(){ WScript.Echo("foo") }());
> #3 - (function(){ WScript.Echo("foo") })();
> 
> #1 is an error. #2 and #3 both work.
> 
> If I type "foo" or if I type ("foo") they are semantically the same
> thing. same as if I type 1 vs (1), etc.
> The fact that "function(){}()" and "( function(){}() )"  are not
> semantically the same seems a bit backwards logically.
> 
> Hence I prefer style #3


Michael,

Yeah that is the way I'm used to seeing this IIFE written.




On Jan 15, 2011, at 1:10 PM, Joe wrote:

> On Jan 15, 2:30 pm, Bill Heaton <[email protected]> wrote:
>> I am curious if anyone can give me insight why the nesting of the function 
>> to be immediately invoked should be completely contained within parenthesis 
>> ( // func  () ); versus parenthesis + parenthesis ( // func )();
>> 
>> I do not get why the parenthesis (and arguments if needed) would be better 
>> placed just inside the final closing parenthesis ')'
> 
> 
> This sounds like something that must have been recently added in the
> latest changes to JSLint. Crockford talks about his preference for
> this convention in the Yahoo video series "Crockford on
> Javascript" (volume three I believe).
> 
> It is of course a matter of style, since the grouping operator is just
> there as a visual designation that the function self-executes, but
> Crockford stated something to the effect that it makes more sense for
> the entire self-executing function (including the actual invocation)
> to be enclosed within the grouping operator, than to leave the
> invocation out.



Joe,

I just recently watched his video on 'the future' and analogy to Walt Disney's 
plans for an EPCOT city; I enjoyed the video, and will be watching more. I do 
agree that it mostly just seems a preference. I had hoped their may be a 
checkbox in JSLint.com to not use his preference on this one when validating 
syntax with his browser tool.

Thanks all,

-Bill Heaton
@pixelhandler



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