Monday, December 25th, 2006

Porting Prototype Enumerable functions to Mootools Array objects

Category: JavaScript, Library, Prototype

<>p>Are you a Mootools user and you wish that you could use the Enumerable coolness from Prototype?

Bas Wenneker has ported the functions over, and has written up the experience.

I really like the Prototype Framework and the functionality that comes with it, but I like Mootools even more because it’s so damn small and lightweight. Sometimes the minimalistic framework is just too light. Recently I needed some of Prototypes’ Enumerable functions for an Array but the app was implemented using Mootools. So I decided to take a look at the Array.each functions provided by the two frameworks. They’re implemented in different ways but by changing the Mootools Array.each I was able to treat a Mootools Array like a Prototype Enumerable. In this article I’ll describe how to ‘hack’ the Enumerable functionality into Mootools. If you just want the code you should take a look at my EnumArray.js.

Related Content:

2 Comments »

Comments feed TrackBack URI

Bas: Why not just create a new Enumerable Class and then implement it in Array? That way, you can use it with other objects as well… That was the original thinking behind keeping it separate in Prototype in the first place.

Comment by Michael — December 27, 2006

Yes you’re right, but I’d like to keep the code more in the spirit of Mootools. I wrote the code with the intention to add maybe 2 or 3 functions to the Array object, not the whole scala of functions from the Enumerable class. In this way I don’t need a new class.

Comment by Bas — December 27, 2006

Leave a comment

You must be logged in to post a comment.