Finding a "safety syntax" for classes

David Herman dherman at
Sun Mar 25 00:15:59 PDT 2012

On Mar 24, 2012, at 10:54 PM, Brendan Eich wrote:

> It's the right trade-off, and not just to get appropriately minimal classes into ES6 -- the computed method case is often part of a generative framework anyway, so won't obviously fit  into any general, declarative syntax.

Since we've gone with the decision not to hoist the initialization of class declarations, I think it makes it easier to conceive of allowing computation in the initialization of a class. Nadav's request is reasonable. Again, I'm fine with deferring it, but it's also fine to discuss it, if only for thinking a step or two down the road.

> At least, this is my gut reaction -- but it would be helpful to see a concrete example in the wild (not contrived) and look deeper.

One simple example that comes to mind: reusing a hand-picked set of generic methods from e.g. Array.prototype or String.prototype:

    class Vector {
        /* various methods... */

        forEach = Array.prototype.forEach; // just an example, don't bikeshed me

        /* more methods ... */

Then again, this example is also in the space of what traits would address, which I think are worth revisiting post-ES6. You could imagine a trait definition like:

    trait Sequence {
        forEach: Array.prototype.forEach,
        /* etc... */

    class Vector with Sequence {
        /* various methods... */

I could imagine keeping the declarative syntax of classes pretty spare by beefing up the expressiveness of traits. But this requires a lot more design work. Again, this is all outside the scope of ES6. Maximal minimalism FTW!


More information about the es-discuss mailing list