3 ms·
Rather than doing this why not just read "JavaScript: The good part" and learn about JavaScript's classes instead.
by sh1mmer 16y ago
Rather than doing this why not just read "JavaScript: The good part" and learn about JavaScript's classes instead.
- code_duck 16y agoI 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.
- the_mitsuhiko 16y ago> I use Crockford's object.beget rather than normal JS constructors, and that works quite fine. Crockford's beget patches on Object which I think is a terrible idea. The main reason why people create class libraries on top of JavaScript is the constructor problem (that setting up the "inheritance chain" triggers the constructor even though we only want the prototype).
- Semiapies 16y agoEmbracing and enhancing prototype style - and perhaps making it clearer in some way - would be very interesting.
- code_duck 16y agoI 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.