so - I'm kind of between jobs and was looking for something to do, when I
came across Def.js <http://github.com/tobeytailor/def.js>. It's a way to
kind of implement a Ruby like inheritance syntax. Anyway, I decided to try
and make one for Class - and this is what came out<http://jsfiddle.net/LnStF/2/>
.
Basically - you can do
new Class.def('Ninja') << new Person({
power:100
});

this will create a Ninja Class, that extends Person, and has a power of 100.

It was actually not as easy as I hoped, since it required monkey-patching
the Class constructor.
At first I tried using valueOf to make the behavior but i was quite confused
with the execution order. Eventually i simply changed the way the
constructor works.

It is obviously just a cool trick. not sure it can be used anywhere, and it
is also counter intuitive for the Mootools Syntax, but i think it's quite a
cool concept.
Limitations - If you simply do:
new Class.def('Person');
without any parameters weird things will happen.
Also - if you forget to use new it won't throw an error but won't work
(execution order problems).

anyways - this is the Forge page <http://mootools.net/forge/p/class_def>.

-- 
Arieh Glazer
אריה גלזר
052-5348-561
5561

Reply via email to