spacer spacer spacer

2006-02-18

Classy Javascript

The Treaty of Orlando notwithstanding, inheritance has become more popular than delegation as a mechanism for doing object-oriented programming.

OpenLaszlo’s LZX language is an attempt to blend the best of both class-based and prototype-based object-oriented programming to provide a powerful interface description language. It has classes, as traditional inheritance-based languages do, but it adds an interesting feature from delegation-based languages: the ability to extend the behavior of a single instance of a class. While it does not permit using an instance as a prototype for another instance, it does make it very easy to turn an extended instance into a class so more instances can be created, or the class further extended.

But, OpenLaszlo is built on Javascript. Which doesn’t (in the currently accepted standard) have classes. It is a prototype-based language.

So, Adam and I spent some time thinking about how to really do class-style inheritance right in Javascript. As he pointed out in his blog entry, the methods that are out there leave a lot to be desired. We know that class- and prototype-based inheritance are equivalent, so it shouldn’t be that hard.

Here’s what we came up with:

Continue reading "Classy Javascript"
18:06 | Link | Reply | Track