4 ms·
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
by code_duck 17y ago
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.
- the_mitsuhiko 17y 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 17y agoEmbracing and enhancing prototype style - and perhaps making it clearer in some way - would be very interesting.
- code_duck 17y 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.