Generator issue: exceptions while initializing arguments

Allen Wirfs-Brock allen at wirfs-brock.com
Sat Sep 8 15:47:05 PDT 2012


On Sep 8, 2012, at 3:20 PM, Brendan Eich wrote:

> SpiderMonkey (Firefox 15 and newer has default parameters):
> 
> js> function f(a = g) { function g(){}; return a; }
> js> f()
> function g(){}
> 
> So function g is hoisted and a defaults to it, as expected.

While I agree that the above is reasonable behavior.  It wasn't the consensus that was reach earlier this year at the Jan.  (or may March??) meeting.  What we agreed upon is that default value expressions in parameter lists have visibility to the left and upward in scope but do not have visibility of anything declared within the curlies that surround the body.   So, in the above example, g should be a reference error when evaluated as a default value initializer.

As the NOTE in step 9 of 10-5-3 says: 

	NOTE	Binding Initialisation for formals is performed prior to instantiating any non-parameter declarations in order to ensure that any such local declarations are not visible to any parameter Initialisation code that may be evaluated. 

Allen


More information about the es-discuss mailing list