Alternative syntax for <|

Russell Leggett russell.leggett at
Thu Nov 17 13:34:05 PST 2011

On Thu, Nov 17, 2011 at 3:06 PM, David Flanagan <dflanagan at>wrote:

>  On 11/16/11 11:45 AM, Erik Arvidsson wrote:
> Sorry for being too brief. Today the following works.
> f();
> ...
> function f() { ... }
> but the following does not:
> f();
> ...
> let f = function f() {};
> I think it is important that we keep the forward reference behavior
> with classes. This requires a declarative way of defining classes.
>  I agree with Erik and Dave that forward references are critical for
> classes.  If we define syntax for classes that is less foward-reference
> friendly than functions are, it will be a source of bugs (speaking from
> personal experience) and be perceived as a step backward.

I agree forward references are important, and the way I see it, there are 3
levels of forward reference.

1. variable hoisting - this can be done with var right now

    var Foo = class {...}

This would allow a function body above it to reference Foo, but not call
new Foo() until after it was defined. This is the limit of what Allen's
operator proposal could do, even with a declarative form 'class Foo {...}'
because it does not create a new function, it depends on the expression
given to class.

2. function hoisting (did I make up this term?) - a function declaration is
capable of not only forward reference, but also forward calling, even
before the declaration is reached in source order. This is the limit of
what current constructor function based class declarations can do. It is
also something that my proposed version of the class operator could do,
because it always creates a function, and could desugar to the same
semantics as the current function style.

3. class hoisting, where all members of the class are available would
require a formal class body instead of an expression, and probably some
restrictions on the class body definition. I don't think any form of class
proposed so far would allow this.

- Russ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list