Posts

Showing posts from November, 2013

Object Oriented JavaScript - Inheritance

Up until now, we've talked about Object Oriented JavaScript  programming. Creating classes though doesn't make you code truly object oriented. What you lack is polymorphism , which is achieved through inheritance. JavaScript is a bit confusing for developers coming from Java or C++, as it's all dynamic, all runtime, and it has no classes at all. It's all just instances (objects). Even the "classes" we simulate are just a function object. Prototype Chain When it comes to inheritance, JavaScript only has one construct: objects. Each object has an internal link to another object called its prototype. That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype. null, by definition, has no prototype, and acts as the final link in this prototype chain . Object.create After being long advocated for ,  EcmaScript 5  has standardized a new method called  Object.create . To keep up with progress, I