Updated OO Library

It has been a while since I last posted and I just wanted to make a quick announcement. Version 2.2 of my Ruby style OO library is now ready for public consumption. It has been sitting around in my darks repository for a good little while now. This new version is functionally identical to the version I last blogged about. The only change I have made is a slight alteration based on some feedback I received from Justin Palmer of EncyteMedia.

In this new version I renamed Class.create to Class.extend, but before you go off on a frantic search and replace. Don't worry, because even though the Class.create method is now deprecated, it won’t disappear for a little while.

So what prompted me to make this change?

Well, Justin pointed a subtle difference between my syntax and the syntax used by Dean Edward's Base.js library.

From Dean Edward's library:

var Square = Shape.extend({ ...
as apposed to my library.

var Square = Class.create(Shape, { ...

In Justin's opinion the syntax of the first version is much more concise than the syntax found in my version. I concur, however in order to achieve that kind of syntax Shape has to have the method extend injected into it's definition by the OO library. This breaks one of the additional set of rules I had defined for my own library. In an effort to make the syntax of my own library a bit more concise I moved the core functionality into Class.extend as seen here.

var Square = Class.extend(Shape, { ...

It's still not nearly as concise, but I feel it is a good compromise. At least the verb extend makes more sense than create in this particular use.

One finally word of warning for those intending to mix my library with Prototype. Even though Class.extend is now the preferred method for creating and extending your own Classes, you are still required to include my library after Prototype in your own work.

Once again head on over to the project page to grab the javascript file.