Javascript inheritance is a multi-horned beast. You can use classical inheritance to make things work a little bit more like Java, or you can subscribe wholeheartedly to doing things Javascript’s way.
Doing things Javascript’s way can be a boon, once you wrap your head around it. You don’t need any helper functions to help you out with this. You don’t need a library to implement useful inheritance, like jQuery or Prototype. You gain the benefits of being able to define private variables for your objects. You do lose a little bit in terms of memory usage. But these days, memory is cheap - and Javascript engines are only getting faster. So why not make it easy on yourself, as a developer - and your users, as downloaders?
You’re also limited in that it’s difficult for an overridden method to access the object’s parent implementation. However, I’m firmly of the belief that if you need to do that, you’re doing it wrong. So, without further ado, let’s delve into how to use Javascript to inherit in style - the Crockford Way.
(more…)