Understanding Javascript Oop

JavaScript is an object oriented (OO) language, with its roots in the Self programming language, although it’s (sadly) designed to look like Java. This makes the language’s really powerful and sweet features stay covered by some pretty ugly and counter-intuitive work-arounds.

One such affected feature is the implementation of prototypical inheritance. The concepts are simple yet flexible and powerful. It makes inheritance and behaviourism first-class citizens, just like functions are first-class in functional-ish languages (JavaScript included).

Fortunately, ECMAScript 5 has gotten plenty of things to move the language in the right way, and it’s on those sweet features that this article will expand. I’ll also cover the drawbacks of JavaScript’s design, and do a little comparison with the classical model here and there, where those would highlight the advantages or disadvantages of the language’s implementation of prototypical OO.

It’s important to note, though, that this article assumes you have knowledge over other basic JavaScript functionality, like functions (including the concepts of closures and first-class functions), primitive values, operators and such…

Understanding JavaScript OOP (killdream.github.com)

Written on January 11, 2012