Skip to content

Commit

Permalink
Changed wording to clarify that function declarations are syntactical…
Browse files Browse the repository at this point in the history
…ly disallowed _directly_ in blocks. Thanks Šime Vidas for a suggestion.
  • Loading branch information
kangax committed Jan 8, 2011
1 parent 71afea0 commit d53420d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,12 @@ <h2 id="expr-vs-decl">Function expressions vs. Function declarations</h2>
Syntactically, they <strong>can not appear in <em>Block</em></strong> (<code>{ ... }</code>) — such as that of <code>if</code>,
<code>while</code> or <code>for</code> statements. This is because <em>Block</em>s can only contain <em>Statement</em>s,
not <em>SourceElement</em>s, which <em>FunctionDeclaration</em> is.
If we look at production rules carefully, we can see that the only way <em>Expression</em> is allowed within <em>Block</em>
If we look at production rules carefully, we can see that the only way <em>Expression</em> is allowed directly within <em>Block</em>
is when it is part of <em>ExpressionStatement</em>. However, <em>ExpressionStatement</em> is explicitly defined
<strong>to not begin with "function" keyword</strong>, and this is exactly what makes <em>FunctionExpression</em>
invalid as part of a <em>Statement</em> or <em>Block</em> (note that <em>Block</em> is merely a list of <em>Statement</em>s).
<strong>to not begin with "function" keyword</strong>, and this is exactly why <em>FunctionExpression</em> cannot appear directly within a <em>Statement</em> or <em>Block</em> (note that <em>Block</em> is merely a list of <em>Statement</em>s).
</p>
<p>
Because of these restrictions, whenever function appears in a block (such as in previous example) it should actually be
Because of these restrictions, whenever function appears directly in a block (such as in the previous example) it should actually be
<strong>considered a syntax error</strong>, not function declaration or expression. The problem is that almost none of the
implementations I've seen parse these functions strictly per rules (exceptions are <a href="http://sourceforge.net/projects/besen/">BESEN</a> and <a href="http://www.digitalmars.com/dscript/">DMDScript</a>). They interpret them in proprietary ways instead.
</p>
Expand Down

0 comments on commit d53420d

Please sign in to comment.