News for hackers. Stuff that matters.
Re:Show HN: Classes for javascript that you'd actually use by mixu on Wednesday January 04, 2012 @08:00AM (#3423918)
Well, how about this? I'm fairly certain it's ES 3 compatible.

https://gist.github.com/1559933

The original was 28 lines, this is 36 (mostly because I like white space).

I haven't ever really tried to emulate classes in JS, but this is probably how I would do it. The major difference is that this is written plain old Javascript rather than some special syntax - easier to understand.

Re:Show HN: Classes for javascript that you'd actually use by bmuon on Wednesday January 04, 2012 @09:16AM (#3424174)
Foo.prototype = new Bar() has the problem of setting the superclass' instance properties as prototype properties of the subclass. This can be solved pretty easily with something like Object.create (the first part explained here http://news.ycombinator.com/item?id=3424156). Here's a different example in 30 lines: https://gist.github.com/1032636