Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Created October 31, 2011 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jashkenas/1327580 to your computer and use it in GitHub Desktop.
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
};
@jashkenas
Copy link
Author

@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