JavaScript Inheritance Sugar
A few days ago, I came across Dean Edward's Base Class for JavaScript Inheritance. I liked the general idea of adding syntactic sugar to JavaScript class-like inheritance. However, I think some things could be improved:
- the code of the Base class is pretty unreadable, because it tries to do too much in too little space
- methods in parent prototypes are called as this.base(), which looks nice but is far from self-explanatory and easily clashes with application methods or properties
- the this.base property is set before each method call, and reset to its previous value afterwards. This isn't very elegant or efficient, and it doesn't deal with exceptions that might be thrown
- extending of priviledged methods is problematic. each constructor in the proto chain that gets called will create its own scope with its own private members and priviledged methods. Overriding priviledged methods will result in those methods operating on a different set of private variables, leading very likely to unexpected results.
| name | type | size |
| base2-demo.html | undefined bytes | |
| base2.js | undefined bytes |