Declarations

Michael O'Brien mob at mbedthis.com
Tue Apr 15 10:56:38 PDT 2008


As a follow up, the following somewhat surprised me.

{
     let b = 1
     {
         function fun() {
             print("CALL: " + b)
         }
     }
}
fun()

gives:

**ERROR** EvalError: uncaught exception: ReferenceError: unresolved  
lexical reference {multiname: [ns public '']::b [ns internal '']::b  
[ns public '__ES4__']::b } (near /Users/dherman/es4/src/builtins/ 
Error.es:86:55-86.55)


ie. the function is hoisted to the outer var block, but does not seem  
to capture the scope chain of where it was declared and b is out of  
scope.

Is this correct or an RI bug?



On Apr 15, 2008, at 9:52 AM, Michael O'Brien wrote:
> Question about declarations:
>
> Consider:
>
> print(Shape.x)
> public class Shape { public static var x = 1; }
> print(Shape.x)
>
> fun()
> function fun() { print("fun"); }
>
>
> In the RI this prints:
>
> undefined
> 1
> fun
>
> In ASC this prints:
> 1
> 1
> fun
>
> What happens in the RI is the class declaration seems to occur where  
> it is coded. It is not being
> hoisted to the top of the enclosing var block. Whereas the function  
> declaration is and thus can
> be called before its declaration.
>
> Is this an RI bug or just a divergence from AS3?
>
> Michael




More information about the Es4-discuss mailing list