An experiment using an object literal based class definitionpattern

Claus Reinke claus.reinke at
Tue Aug 9 01:18:02 PDT 2011

> The name resolution rules we agreed to permit mutually recursive
> functions without hoisting (or you could view those rules as hoisting
> everything):
> let f1 = function() {f2()};
> let f2 = function() {f1()};
> f1();  //happily recurs until it it runs out of stack

Sorry, I seem to have missed that discussion - are those new rules
documented somewhere? I had some concerns about the old rules,
and would like to check whether those are resolved.

> and hoisting doesn't prevent this sort of error with tail-end function
> declarations:
> f1();  //error because foo not yet initialized;
> ...
> let foo="foo"
> function f1() {print(foo)};

Indeed, that is the main flaw in the idea of using hoisting as a substitute
for letrec: mixing declarative and imperative forms. I've been tempted to
suggest that function declarations are hoisted only within their group of
declarations. In other words, in code like this

    function A() {..}
    function B() {..}
    var X = ..;
    function C() {..}
    function D() {..X..}

A/B could be mutually recursive, and C/D could, but A/B could not
forward reference C/D. That would still allow hoisting to emulate

        <mutually recursive fundefs>
    in <code>

and it would avoid the trap of hoisting D outside the validity of X.
As a downside, one could no longer use hoisting to emulate

        <mutually recursive fundefs>


More information about the es-discuss mailing list