Friday, November 30, 2012

A Clarification on what MooTools Class Implement does

If you search the net in the above topic "MooTools implement vs extend", you'll find loads of results.

There's a reason for that. MooTools has a quite misleading name on what "Implements" does in their framework. It's a mixin. Not an "Implement". It mixes the source's properties into the target.

"Implement" in programming terms usually means implementing an interface. I.e. crafting some concrete stuff following an abstract description. So there is an abstract->concrete momentum. There is no such momentum in MooTools' "Implement". It's a plain, non-deep copy between two independent, concrete stuff. They use it as a synonim as "apply".

Just look what they say in the docs:
Implements the passed in properties into the base Class prototypes, altering the base Class. The same as creating a new Class with the Implements property, but handy when you need to modify existing classes.
Watch the wording. First word should be "Mixes" or "Merges". I bet there would not be such an amount of incomprehension.

1 comment:

  1. It does not only mix / merge from another class. see the source. https://github.com/mootools/mootools-core/blob/master/Source/Class/Class.js#L107

    see http://jsfiddle.net/GGgEv/ - a mere merge won't run the methods of the mixin class.

    ReplyDelete