class as the dual to new
russell.leggett at gmail.com
Fri Nov 4 11:58:55 PDT 2011
I just wanted to point something out that strikes me as very elegant while
we debate the minimalist class proposals set forth by Jeremy, Brendan etc.
If we do go with the approach of class taking an object literal, and more
specifically if it can take an arbitrary object instead of *having* to be a
literal, something very interesting falls out of it. The class keyword
becomes *almost* the dual of new.
let m = new Monster();
let M2 = class m;
The result of this should be a class M2 which works exactly the same way as
the original Monster class. The only thing that would really be off would
be than any resulting instance data from calling new Monster() would result
in extra properties on the prototype. I'm not saying that class should be
capable of round tripping from new and back, but rather that I think looked
at in this light, it should make class an intuitive construct, and fill a
whole in the language.
As for the questions it raises regarding super, and some fuzzy notion of
copying, I try to address that in my full proposal here
I basically think that super should be tied to extension, and therefore not
cause problems with non-literal class bodies as long as extension is
orthogonal to classes.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss