Re: [JSMentors] Immediately invoked function error explanation

2011-01-03 Thread Lasse Reichstein
On Mon, 03 Jan 2011 16:14:55 +0100, Dmitry Soshnikov wrote: Yes, the thing I wanted to underline, that the parser (because of "ExpressionStatement" cannot begin with a `function` keyword) always treats such production as a `FunctionDeclaration`. And that the `SyntaxError` relates to two

Re: [JSMentors] Immediately invoked function error explanation

2011-01-03 Thread Dmitry Soshnikov
Sure, for those who wrote an ES parser (Hello, Peter ;)) this question shouldn't be hard. And of course the parser themselves are good helpers in this case. Dmitry. On Mon, Jan 3, 2011 at 5:52 AM, Ariya Hidayat wrote: > If you have latest command-line SpiderMonkey or my little tool > 'SyntaxJS'

Re: [JSMentors] Immediately invoked function error explanation

2011-01-03 Thread Dmitry Soshnikov
On Sun, Jan 2, 2011 at 10:44 PM, Diego Perini wrote: > On Sat, Jan 1, 2011 at 12:00 PM, Dmitry A. Soshnikov > wrote: > > On 01.01.2011 2:43, fernando trasvina wrote: > >> > >> Hi. very nice explanation but what i don't fully understand is why the > >> grouping operator makes the parenthesis follo

Re: [JSMentors] Immediately invoked function error explanation

2011-01-03 Thread Dmitry Soshnikov
Yep, it's also quite a good explanation. Dmitry. On Sun, Jan 2, 2011 at 5:32 PM, fernando trasvina wrote: > > On Jan 1, 2011, at 5:00 AM, Dmitry A. Soshnikov wrote: > > On 01.01.2011 2:43, fernando trasvina wrote: > > Hi. very nice explanation but what i don't fully understand is why the > group

Re: [JSMentors] Immediately invoked function error explanation

2011-01-03 Thread Dmitry Soshnikov
On Sun, Jan 2, 2011 at 3:14 PM, Lasse Reichstein wrote: > On Fri, 31 Dec 2010 14:46:37 +0100, Dmitry A. Soshnikov < > dmitry.soshni...@gmail.com> wrote: > > So, why does this code produces a SyntaxError: >> >> function () { >> ... >> }() >> > ... > > Try to provide as much complete explanatio

Re: [JSMentors] Immediately invoked function error explanation

2011-01-02 Thread fernando trasvina
Hey very nice tool Sent from my iPhone On Jan 2, 2011, at 8:52 PM, Ariya Hidayat wrote: If you have latest command-line SpiderMonkey or my little tool 'SyntaxJS' (see https://github.com/ariya/syntaxjs for the code), you can see the syntax tree produced by the parser. For the case: funct

Re: [JSMentors] Immediately invoked function error explanation

2011-01-02 Thread Ariya Hidayat
If you have latest command-line SpiderMonkey or my little tool 'SyntaxJS' (see https://github.com/ariya/syntaxjs for the code), you can see the syntax tree produced by the parser. For the case: function foo(x) { alert(x); }(1); the output looks like: { "type": "Program", "

Re: [JSMentors] Immediately invoked function error explanation

2011-01-02 Thread Diego Perini
On Sat, Jan 1, 2011 at 12:00 PM, Dmitry A. Soshnikov wrote: > On 01.01.2011 2:43, fernando trasvina wrote: >> >> Hi. very nice explanation but what i don't fully understand is why the >> grouping operator makes the parenthesis following the function declaration >> work as call. >> >> (function(x){

Re: [JSMentors] Immediately invoked function error explanation

2011-01-02 Thread fernando trasvina
On Jan 1, 2011, at 5:00 AM, Dmitry A. Soshnikov wrote: > On 01.01.2011 2:43, fernando trasvina wrote: >> Hi. very nice explanation but what i don't fully understand is why the >> grouping operator makes the parenthesis following the function declaration >> work as call. >> >> (function(x){aler

Re: [JSMentors] Immediately invoked function error explanation

2011-01-02 Thread Lasse Reichstein
On Fri, 31 Dec 2010 14:46:37 +0100, Dmitry A. Soshnikov wrote: So, why does this code produces a SyntaxError: function () { ... }() ... Try to provide as much complete explanation as possible. Also try to answer without cheating ;) Because an ExpressionStatement may not start with th

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Dmitry A. Soshnikov
I'm going to vacation, so tomorrow I won't be online, will answer later if something. Happy New Year again for everyone ;) Dmitry. On 02.01.2011 1:27, Dmitry A. Soshnikov wrote: On 02.01.2011 1:22, Garrett Smith wrote: On 1/1/11, Dmitry A. Soshnikov wrote: On 02.01.2011 0:27, Garrett Smith

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Dmitry A. Soshnikov
On 02.01.2011 1:22, Garrett Smith wrote: On 1/1/11, Dmitry A. Soshnikov wrote: On 02.01.2011 0:27, Garrett Smith wrote: On 1/1/11, Dmitry A. Soshnikov wrote: On 01.01.2011 4:01, Garrett Smith wrote: The correct answer is that it's function declaration! And from this step, there are two reas

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Garrett Smith
On 1/1/11, Dmitry A. Soshnikov wrote: > On 02.01.2011 0:27, Garrett Smith wrote: >> On 1/1/11, Dmitry A. Soshnikov wrote: >>> On 01.01.2011 4:01, Garrett Smith wrote: >>> The correct answer is that it's function declaration! And from this >>> step, there are two reasons of the issue. >>> >> No, t

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Dmitry A. Soshnikov
Notice though, that I started the thread that explanation were _incomplete_. I don't say they are completely were wrong. Again, they were just incorrect in respect of the SyntaxError _reasons_. Of course if the explanation is started from: /"we need to have a function expression here, and there

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Dmitry A. Soshnikov
On 02.01.2011 0:27, Garrett Smith wrote: On 1/1/11, Dmitry A. Soshnikov wrote: On 01.01.2011 4:01, Garrett Smith wrote: On 12/31/10, fernando trasvina wrote: why this is not treated the same way as: function(x){}(1); That is a SyntaxError. The most recent message on this thread (mine),

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Garrett Smith
On 1/1/11, Dmitry A. Soshnikov wrote: > On 01.01.2011 4:01, Garrett Smith wrote: >> On 12/31/10, fernando trasvina wrote: >> >> >>> why this is not treated the same way as: >>> >>> function(x){}(1); >>> >> That is a SyntaxError. The most recent message on this thread (mine), >> explains that the

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Jose Antonio Perez
Happy new year ;) > Remember, a A FunctionDeclaration's function is added to the > VariableEnvironment in Variable Instantiation. It is not and cannot be an > ExpressionStatement. > > An FunctionExpression is an ExpressionStatement; it is not bound to the VE > (VariableEnvironment) on entering an

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Dmitry A. Soshnikov
On 01.01.2011 13:42, Dmitry A. Soshnikov wrote: On 01.01.2011 4:01, Garrett Smith wrote: On 12/31/10, fernando trasvina wrote: why this is not treated the same way as: function(x){}(1); That is a SyntaxError. The most recent message on this thread (mine), explains that the production for

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Dmitry A. Soshnikov
On 01.01.2011 0:55, Marc Harter wrote: The thing is that (almost?) all explanations (I repeat -- books, articles, etc) talked about `calling`, that is wrong. While the reason is that parentheses at the end are not parentheses of a call (`Arguments` production), but just a grouping operator (wi

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Dmitry A. Soshnikov
On 01.01.2011 2:08, Garrett Smith wrote: On 12/31/10, Marc Harter wrote: The thing is that (almost?) all explanations (I repeat -- books, articles, etc) talked about `calling`, that is wrong. While the reason is that parentheses at the end are not parentheses of a call (`Arguments` production),

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Dmitry A. Soshnikov
On 01.01.2011 2:43, fernando trasvina wrote: Hi. very nice explanation but what i don't fully understand is why the grouping operator makes the parenthesis following the function declaration work as call. (function(x){alert(x)}(1)); why this is not treated the same way as: function(x){}(1);

Re: [JSMentors] Immediately invoked function error explanation

2011-01-01 Thread Dmitry A. Soshnikov
On 01.01.2011 4:01, Garrett Smith wrote: On 12/31/10, fernando trasvina wrote: why this is not treated the same way as: function(x){}(1); That is a SyntaxError. The most recent message on this thread (mine), explains that the production for ExpressionStatement explicitly forbids an Express

Re: [JSMentors] Immediately invoked function error explanation

2010-12-31 Thread Garrett Smith
On 12/31/10, fernando trasvina wrote: > Hi. very nice explanation but what i don't fully understand is why the > grouping operator makes the parenthesis following the function declaration > work as call. > Did you read the last message I posted? > (function(x){alert(x)}(1)); > That is a Functio

Re: [JSMentors] Immediately invoked function error explanation

2010-12-31 Thread fernando trasvina
Hi. very nice explanation but what i don't fully understand is why the grouping operator makes the parenthesis following the function declaration work as call. (function(x){alert(x)}(1)); why this is not treated the same way as: function(x){}(1); On Dec 31, 2010, at 7:46 AM, Dmitry A. Soshnik

Re: [JSMentors] Immediately invoked function error explanation

2010-12-31 Thread Garrett Smith
On 12/31/10, Marc Harter wrote: > >> The thing is that (almost?) all explanations (I repeat -- books, articles, >> etc) talked about `calling`, that is wrong. While the reason is that >> parentheses at the end are not parentheses of a call (`Arguments` >> production), but just a grouping operator

Re: [JSMentors] Immediately invoked function error explanation

2010-12-31 Thread Marc Harter
> The thing is that (almost?) all explanations (I repeat -- books, articles, > etc) talked about `calling`, that is wrong. While the reason is that > parentheses at the end are not parentheses of a call (`Arguments` > production), but just a grouping operator (without an expression inside) > w

Re: [JSMentors] Immediately invoked function error explanation

2010-12-31 Thread Dmitry A. Soshnikov
On 31.12.2010 19:16, Marc Harter wrote: The correct and full explanation is here: http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses This is good Dmitry, thanks for sharing, I understood what you could and could not do but didn't know the reasons

Re: [JSMentors] Immediately invoked function error explanation

2010-12-31 Thread Marc Harter
> The correct and full explanation is here: > http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses This is good Dmitry, thanks for sharing, I understood what you could and could not do but didn't know the reasons to that depth. -- To view archived d

[JSMentors] Immediately invoked function error explanation

2010-12-31 Thread Dmitry A. Soshnikov
Just for those who don't use Twitter. I've just edited my "ES3.Ch5.Functions" article in respect of explanation the "surrounding parentheses". The thing is, that almost _all_ explanations (in books, articles, etc) were at least very incomplete (and even wrong). So, why does this code produces