4 ms·
Ask HN: Is there a consensus on the way to do JS inheritance?
I work on a project that uses classes in JS. So far I've already used 3 different ways to do inheritance:
- Subclass.prototype = new Class()
- Subclass.prototype = Object.create( Class.prototype )
- Fiber: https://github.com/linkedin/Fiber
None of those solutions were acceptable: the two firsts have issues with method overriding and super() invocation, the latter is too verbose to implement.
It seems that most articles on the subject link to John Resig's Simple Javascript Inheritance: http://ejohn.org/blog/simple-javascript-inheritance/, but that one is from 2008 and I was wondering if there's one "modern" way to do JS inheritance and that most people agree on.
Is there such a thing? Is there a library that implements it?
Side note: Please avoid things like "you're trying to do things that JS is not meant for", I'm just trying to answer the how, not the why.
- tgriesser 12y agoI think your best bet would be going with something like node.js' util.inherits, a standalone version for the browser can be found here: https://github.com/isaacs/inherits https://github.com/isaacs/inherits
- deleted 12y ago[deleted]