Archives For John Resig

… or how to stand on the shoulders of giants.

i’m sure that most of you who are interested in this post will be somewhat familiar with this John Resig post of 2008, where he outlines a simple process for creating object (class?) hierarchies in JavaScript.

as a relative newcomer to JavaScript after 20 years of C/C++/C# development, the last few months have provided a fun challenge. I cut my JavaScript teeth developing the HTML5 ebook From Blue To Red, and that experience provided an excellent opportunity to match my preconceptions of strongly-typed classical inheritance to the strange new world of JavaScript prototypes.

i’m now working on another project which is modeled well with a couple of shallow class hierarchies, and the JavaScript components cannot depend on any other libraries during a bootstrap phase. Resig’s pattern provided an excellent starting point for me, but I ran into trouble when I started using ECMAScript 5 getter and setter properties, which were actually being invoked on reference when copying properties from the object literal to the class prototype.

here then is a version of Resig’s Simple JavaScript Inheritance, revisited and revised for ECMAScript 5 and compliance with “use strict”.

Continue Reading…