-
-
Save jashkenas/1327580 to your computer and use it in GitHub Desktop.
// From: https://mail.mozilla.org/pipermail/es-discuss/2011-October/thread.html#17696 | |
const className = superClass <| function(/*constructor parameters */) { | |
//constructor body | |
super.constructor(/*arguments to super constructor */); | |
this.{ | |
//per instance property definitions | |
}; | |
}.prototype.{ | |
//instance properties defined on prototype | |
}.constructor.{ | |
//class (ie, constructor) properties | |
}; |
It seems that you both have a lot of knowledge in what isn't good as a class syntax. I would guess you have as much knowledge on what is good. Could you please enlighten the es-discuss thread? It is open to ideas from anyone.
@DavidBruant: I'm wary of wading in to es-discuss when it's easier to snipe from the sidelines ;)
But in all seriousness, my ideas about a rough direction for JavaScript classes that desugar into pure ES3 prototypes are pretty well covered here: http://jashkenas.github.com/coffee-script/#classes (If you add back JS function syntax, and some braces around the class body).
It sure looks weird to me !
Why not stick with http://wiki.ecmascript.org/doku.php?id=harmony:classes#the_proposal_in_a_nutshell
That looks way better, doesn't it ?
I've been playing around with the (current) Harmony class implementation proposal up on http://wiki.ecmascript.org/doku.php?id=harmony:classes#the_proposal_in_a_nutshell and I personally found it very usable and easy to grasp. I wouldn't change that (the superclass stuff earlier in this thread however I am not a fan of).
@jashkenas looking through the other libraries referenced on http://jashkenas.github.com/coffee-script/#classes, is there any one you would say closely matches the implementation of syntactic class sugar you offer through CS at the moment?. I ask as it would be interesting to know from a JS-perspective for anyone that does want to use 'classes' without explicitly coding with prototypal inheritance in mind (even if that does happen behind the scenes).
@addyosmani: All of the various class libraries work more or less the same way, with different levels of extra features. Resig's simple inheritance is about as minimal as it gets, whereas JS.Class has all kind of extra hooks and goodies in it.
CoffeeScript's classes are just simple proper prototype chain inheritance, combined with sugar for easily calling super. The main bonus feature that isn't (and can't be) mimicked in a JavaScript library is executable class bodies.
This is truly frightening. Sadly it doesn't look like a huge number of the ideas in the rest of the associated thread (https://mail.mozilla.org/pipermail/es-discuss/2011-October/017758.html) are that much better.. :(