

Classy: Classes for Javascript - whalesalad
http://classy.pocoo.org/

======
jeresig
Huh, weird. This seems to crib very heavily from my original Simple JavaScript
Inheritance implementation: <http://ejohn.org/blog/simple-javascript-
inheritance/>

It even uses the 'classy' name and logo (stemming from an April Fools joke
that I ran that used the aforementioned inheritance implementation):
<http://ejohn.org/blog/classy-query/>

Seems like he may have made some improvements to the code (using
hasOwnProperty and putting a try/finally around the code block are two changes
that I see) but on the whole it looks very very similar to the original
implementation that I wrote. Odd.

Update: It seems as if the author credits the original code in a tweet that he
made: <http://twitter.com/mitsuhiko/status/12902227050>

~~~
hammerdr
The reversal of the "extends" paradigm is interesting. It seems very natural.
What made you go with that?

(I know I'm not really responding to your comment but I think it speaks for
itself).

~~~
jeresig
Good question - I was inspired heavily by Dean Edwards' original Base Class
library, it seemed to make the most sense when I was using it.

The original code: <http://dean.edwards.name/weblog/2006/03/base/>

The current code:
[http://code.google.com/p/base2/source/browse/trunk/src/base2...](http://code.google.com/p/base2/source/browse/trunk/src/base2/Base.js)

------
whalesalad
Another handy class library that I have been using a while -
[http://justin.harmonize.fm/index.php/2009/01/cobra-a-
little-...](http://justin.harmonize.fm/index.php/2009/01/cobra-a-little-
javascript-class-library/)

Now I tend to write my "classes" like this: <http://gist.github.com/380000>

This is using the traditional prototype method. It involves a bit more syntax,
but it doesn't require any extra libraries.

------
maccman
This is my take on it - few less dollars and underscores:
[http://github.com/maccman/supermodel-
js/blob/master/supercla...](http://github.com/maccman/supermodel-
js/blob/master/superclass.js)

------
sh1mmer
Rather than doing this why not just read "JavaScript: The good part" and learn
about JavaScript's classes instead.

~~~
code_duck
I do wonder why so many people want to have class-based, traditional
inheritance in JavaScript. Why not just embrace the prototype based style? I
use Crockford's object.beget rather than normal JS constructors, and that
works quite fine.

On the other hand, the mechanism of classical inheritance is well understood,
and I do miss conveniences like __init__ and subclassing.

~~~
Semiapies
Embracing and enhancing prototype style - and perhaps making it clearer in
some way - would be very interesting.

~~~
code_duck
I think that the 'beget' style does just that. Instead of requiring a special
constructor, it provides a clear way to duplicate an object - just what
prototypical inheritance is meant to be.

