Created
October 31, 2011 14:15
-
-
Save jashkenas/1327580 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
}; |
@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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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).