I present the result below, wrapped up for require.js. There is really very little code indeed – just two functions: inherit and superConstructor.
The contents of inherit are much as you’ll find in many a blog post, though there’s a surprising amount of subtle variation out there!
More interesting is superConstructor, which employes a somewhat offensive tactic to allow calls all the way up the constructor chain. What makes this difficult is that ‘this’ must remain the actual object being constructed throughout those nested calls, so we need to manually provide the context to know what the next constructor up the chain is.
Having done this and saved the code above into clazz.js, we can write code with inheritance as follows (working example as a jsfiddle).
To be fair, my super-simple inheritance library is extremely restricted in its abilities, for instance not handling constructor parameters. But that’s because I didn’t need them, and any extra features should be easy to add. Most of all it was a valuable learning experience.
* Actually I love an off-the-shelf library as much as the next chap (or chappess) – but if you don’t feel comfortable with the libraries on offer and the problem seems nicely tractable and a worthwhile learning experience then why not go for it. You can always change your mind.