Function declarations in statements

Igor Bukanov igor at mir2.org
Sat Mar 17 05:09:08 PDT 2007


On 17/03/07, Igor Bukanov <igor at mir2.org> wrote:
> For me JScript behavior is in fact more consistent. There both var and
> function statement is executed on the function entrance no matter
> where they are placed.

This also suggest a more reasonable behavior than the current mess:

Make a function statement to define its name as a local variable for
the whole function/script it exists in in the same way as the var
statement does but execute their declarations at the entrance of the
block they are defined in.

var x = 20;
function f() {
    print(x); // Should print undefined as the function statement in
the block bellow
               //  defines x as a local variable with the undefined as
the initial value
    {
        print(x); // Should print the definition of function x as it
is executed on the block
                    // entrance
        function x() { }
    }
}

With this rule the function statements inside blocks are no longer
special compared with top-scope definitions and consistent with the
var behavior. It should also be compatible with SpiderMonkey behavior
in reasonable programs.

Regards, Igor



More information about the Es4-discuss mailing list