Subj : Re: function expression To : netscape.public.mozilla.jseng From : Martin Honnen Date : Sat Jan 17 2004 04:19 pm Georg Maaß wrote: > This works: > > js> (function banana(){banana.taste='fruchtig';print(banana.taste);})(); > fruchtig > > This fails: > > js> function banana(){banana.taste='fruchtig';print(banana.taste);}(); > 94: SyntaxError: syntax error: > 94: function banana(){banana.taste='fruchtig';print(banana.taste);}(); > 94: ................................................................^ > > Why is this not recognized as function expression? The compiler assumes > that this is a function declaration, but it is a function expression. If > this is invalid, how can I detect this from the spac, that this is invalid? Looking at the ECMAScript edition 3 specification section 14 defines a Program to consist of SourceElements where a SourceElement is a Statement or a FunctionDeclaration. When SourceElements is evaluated it is processed first for function declaration then the statements are evaluated. A FunctionDeclaration is defined as function Identifier ( FormalParameterListopt ) { FunctionBody } so the part function banana(){banana.taste='fruchtig';print(banana.taste);} matches that and what remains is (); and that doesn't follow the rules for any statement possible I think. -- Martin Honnen http://JavaScript.FAQTs.com/ .