- We design and build extraordinary applications for companies looking to make the next great idea a reality.
- learn more
Developer’s Notebook: Useful OO JavaScript resources
My post about learning to organize classes without the semantic sugar of Prototype earned me some wide-ranging comments here and on Ajaxian. My favorite was Isaac Z. Schlueter Matthew Smith's proposal of a new framework: JLJ (Just Learn JavaScript). To that end, I thought I'd compile some of the most useful sites and posts I've come across in my quest over the last couple of years to employ better inheritance strategies in my JavaScript.
Let's face it, in the wide world of web development, for every
dedicated client-side developer with a real taste for JavaScript, there
are 10 Java middleware developers who believe that JavaScript isn't a
"real" object-oriented language. Programmers with a broad range of
experience in a wide array of languages will argue that JavaScript's
loose typing, dynamic nature and prototype-based inheritance scheme are
actually far more "object-oriented" than, say, Java or C++. That may be
true, but there are lots of folks out there writing production code who
have never written complex software using any language _but_
JavaScript. For these folks, myself included, JavaScript's dynamism is
both a blessing and a curse. There's a lot of freedom, but not a lot of
guidance. Languages that rely on good developer
behavior rather than the intrisic properties of the language themselves
can be dangerous. Just enough rope to hang yourself, and all that jazz. For those of us whose primary language is JavaScript, a little structural guidance can help a lot.
As the inestimable Douglas Crockford illustrates in Classical Inheritance in JavaScript, the main benefit to inheritance in a dynamic language is re-use. Most of us are interested in getting the most mileage possible out of every line of code we write. Many JavaScript frameworks enforce or encourage a particular method of doing this; most are modeled on the classical inheritance schemes of other languages. Every serious student of JavaScript should learn the strengths and weaknesses of these patterns - and how to implmenet them on the fly, without a framework to fall back on.
A note on this list: It's a highly subjective smattering of articles I found useful. Some are high-level discussions of JS itself, or of inheritence strategies in general. Others grapple with the interitance models of specific libraries in ways that highlight the underlying issues. I could post a completely separate list of JS/Ajax frameworks and their various approaches to the topic. But that's a different post for a different day.
On to the list:
Inheritance Strategies
- JavaScript: The World's Most Misunderstood Programming Language: Another Crockford classic. Start with this, graduate to the aforementioned inheritance article, and then lose a few days in the wilds of his site.
- Private Members in JavaScript: While you're there, check out this piece.
- Objectifying JavaScript: A strong tutorial from Digital Web.
- OOP in JS: An older but still-relevant multi-part case study in how to mimic class-based inheritance in JS.
- Correct OOP for Javascript: A didactic but persuasive look at classical inheritance models.
- Object Oriented Programming in JavaScript: A fairly dry but compelling paper examining a couple of different class-building strategies, based on an earlier 2003 paper.
- Prototype: Inheritance Madness: An examination of Prototype's approach to classes.
- Base: A JavaScript inheritance framework.
Closures, the Global Namespace and the Module Pattern
- Global Domination: A seminal YUI blog post about the dangers of the global namespace.
- Javascript Closures for Dummies: The title says it all...
- JavaScript Closures ... but this one says it more succinctly.
- A JavaScript Module Pattern: Another YUI blog post, this one annotating Crockford's module pattern.
- YUI's Module Pattern vs. Prototype's Class Function: Isaac Z. Schlueter's interesting post on Crockford's module pattern and how to extend it into a reusable constructor.
- Show love to the Module Pattern: More commentary on the module pattern.
Singletons, Lazy Constructors and Memoization
- JavaScript: The Singleton Design Pattern: A quick overview of singletons, with an interesting perspective on anonymous constructors.
- Lazy Function Definition Pattern: A blog entry from a functional-programming viewpoint.
- One-Line JavaScript Memoization: How to save overhead by doing the hard stuff once and saving it off.
Further Reading: DSLs, Aspect-Oriented Programming and More
- Metaprogramming JavaScript Presentation: Domain-specific languages and JavaScript.
- AspectJS: An AOP library for crosscutting concerns.
- Scope in JavaScript: Another piece from Digital Web, this time tackling how to master the this keyword, Function.apply and Function.call.
- Seven JavaScript Techniques You Should Be Using Today: Not specifically devoted to OOP, but a good roundup of best practices in general.
Comments: 1 so far
Leave a comment
About Pathfinder
Recent
- Firefox Plugin Malware ‘Trojan.PWS.ChromeInject.A’
- Pathfinder releases version 1 of the its Flash Platform microsite (codename Mica)
- Pimp my Rails: Five Plugins & Gems to Make Rails Better
- iPhone: Using Pre-processor Directives for Device Testing
- Subtle OpenGL Projection Matrix Difference Between iPhone Simulator and Device
- App Security: Throw Out the Org Chart!
- Pimp my jQuery: Five plugins to replace the features Prototype and Scriptaculous users expect
- Thanksgiving 2008: What We’re Thankful For (In Rails)
- iPhone SDK: Testing with TextMate & GTM
- GWTQuery - JQuery-like Syntax in GWT
Archives
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006


Thanks for the link to my site, Brian, but credit where credit’s due: The “JLJ” comment (which I must assume was tongue-in-cheek) was posted by Matthew Smith. Mine was the comment above that one, about turning Javascript into other languages.
This is a very interesting list, and I’m familiar with about half of these articles. Thanks for assembling it, I’ve bookmarked this and will certainly be back to read through the others.
Comment by Isaac Z. Schlueter, Friday, August 24, 2007 @ 6:50 pm