6 ms·
Well, how about this? I'm fairly certain it's ES 3 compatible. https://gist.github.com/1559933 https://gist.github.com/1559933 The original was 28 lines, this
by mixu 15y ago
Well, how about this? I'm fairly certain it's ES 3 compatible.
https://gist.github.com/1559933 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.
- bmuon 15y agoFoo.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 http://news.ycombinator.com/item?id=3424156). Here's a different example in 30 lines: https://gist.github.com/1032636 https://gist.github.com/1032636