jQuery, object inheritance and JSON

When developing a hobby project of mine, I previously used both MooTools and jQuery as embedded toolkits. Now, however, I have decided to exclude MooTools and only keep jQuery.

MooTools have some really nice features, but since i only used its object inheritance and JSON implementation, I decided to exclude it in the upcoming 1.0 release. The less 3rd part components, the better.

Class inheritance

When I no longer have the MooTools Object class, I use the jQuery extend function to create inheriting classes, as such:

function InheritingClass() {
   $.extend(this, new BaseClass("optional parameters"));
};

while the MooTools Object class required a syntax like this:

var InheritingClass = Class({
   Extends: BaseClass,
   initialize: function() { this.parent("optional parameters"); }
});

The later example requires knowledge about the MooTools object model, while the first only requires that developers know how to use the extend method.

JSON encoding/decoding

MooTools features a nice JSON encode/decode implementation, which I will thus not be able to use anymore, so I had to find an alternative.

jQuery contains (at least) two functions that can be used to handle JSON – parseJSON and serializeArray. However, the later only works with DOM elements, so it is not really what I was after.

After doing some reading, it seems like the official json.org JSON JavaScript implementation is the best around, while a jQuery plugin that I found had quite an extensive issue list.

So, although it makes me depend on yet another 3rd part component, I chose this nice little class, which I have used before. MooTools is hereby completely replaced with jQuery (and the small JSON class).

Advertisements