New Class Initialize in Mootools 1.2.2

Posted by Sean on Apr 24, 2009 under

Just a quickie: I was browsing the new Class script of Mootools 1.2.2 , to learn about all the changes (which are quite awesome), and I hope to rework my Privates Mutator real soon to work with the new way of things. I noticed this immediately:

if (params instanceof Function) params = {initialize: params};

If you only pass in a function , instead of an Object with functions in it, then that function will be the initialize (or constructor) of your class.

So instead of:


var Test = new Class({
    initialize:function() {
        console.log('testing');
    }
});

you can now write:


var Test = new Class(function() {
    console.log('test');
});

I'm not quite sure of a good use for this, but if you just needed a quickie class that you just want to instantiate and that's it, then this is for you!

Add a Comment

Search

Categories

Treats

  • No RSS feed found.
See all »