Pages

Sunday, August 31, 2014

Javascript Prototypal Inheritance

Everything in JavaScript is an object. There are no classes. So when we talk about inheritance, we are talking about objects directly inheriting from other objects. To achieve inheritance, broadly speaking, we need to store the reference of the parent in the child somewhere. When a property look-up happens in the child, the child is searched first, and if the property is not found there, we move to its parent and search. And so on, until we hit the end of the inheritance chain.