Hi Jeremy,

Thanks for the proposal. I've been advocating a minimalist approach to classes 
for a while now; I think it's a good goal. A few of us sketched out something 
similar on a whiteboard in the last face-to-face meeting; at least, it used the 
object literal body. We hadn't thought of two of your ideas:

1) allowing class expressions to be anonymous
2) allowing the RHS to be an arbitrary expression

I like #1; we have a lot of agreement around classes being first-class, and 
that just fits right in.

But with #2 I'm not clear on the intended semantics. You say this could be 
desugared but don't provide the details of the desugaring. The RHS is an 
arbitrary expression that evaluates to the prototype object (call it P), but 
the extends clause is meant to determine P's [[Prototype]], right? Do you 
intend to mutate P's [[Prototype]]? I wouldn't agree to that semantics.

Another thing that this doesn't address is super(). Right now in ES5 and 
earlier, it's pretty painful to call your superclass's constructor:

    class Fox extends Animal {
        constructor: function(stuff) {
            Animal.call(this, stuff);
            ...
        }
    }

In general, I think your arbitrary-expression-RHS design is incompatible with 
the super keyword, which needs to be lexically bound to its class-construction 
site. I'll have to think about it, though.

However, I think the approach of an object literal body (and only an object 
literal body) works well. I suspect you could still implement all your examples 
of dynamically-computed classes, although probably with a little more work in 
some cases.

Dave

On Oct 31, 2011, at 6:57 PM, Jeremy Ashkenas wrote:

> 'Evening, ES-Discuss.
> 
> After poking a stick in the bees' nest this morning (apologies, Allen), and 
> in the spirit of loyal opposition, it's only fair that I throw my hat in the 
> ring. 
> 
> Here is a proposal for minimalist JavaScript classes that enable behavior 
> that JavaScripters today desire (as evidenced by libraries and languages 
> galore), without adding any new semantics beyond what already exists in ES3.
> 
> https://gist.github.com/1329619
> 
> Let me know what you think, and feel free to fork.
> 
> Cheers,
> Jeremy Ashkenas
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to