Description: Precisely because MooTools is based on OO ideas, the idea of OO is fully used in MooTools's own functions-inheritance and implementation. MooTools provides a set of basic functional classes: Chain,events,options,group, Then we can extend them to implement the functionality they provide in our classes. These basic functional classes are implemented by MooTools the AJAX,XHR and Fx.base classes that they provide.
Note: In general, chain,events and options are not used alone and will be extended by other classes (implement) to provide enhancements to these classes
1. Class: Chain
Function: Here the chain class organizes function into a chain structure.
Method:
Chain: Add a function to the chain
Callchain: The first function in the chain is executed and then deleted (the second function in the chain will change to a new
The top of the chain)
Clearchain: Clear all functions in chain
Example:
var c = new Chain (). Chain (function () {
Alert (' Func a! ');
}). Chain (function () {
Alert (' Func b! ');
}). Chain (function () {
Alert (' Func c! ');
});
C.callchain (); "Func a!"
C.callchain (); "Func b!"
C.callchain (); "Func c!"
2. Category: Events
Role: In layman's terms, it's actually like an event manager (everyone feels that most of the cases should be
Custom events). Other classes can implement it for their own event management.
Method:
Addevent: Adds a listener for the specified event to the organizer
FireEvent: Triggers the execution of all listener methods under the specified event
Removeevent: Removes the listener for the specified event from the organizer
Example:
var Evts = new Events ();
var fa = function (e) {
Alert (' aaaaaaa ');
};
var fb = function (e) {
Alert (' bbbbbbb ');
};
Evts.addevent (' onmyevent ', FA). Addevent (' MyEvent ', FB);
Evts.fireevent (' onmyevent '); First alert out "AAAAAAA", then alert out "BBBBBBB"
Evts.removeevent (' onmyevent ', FA);
Evts.fireevent (' onmyevent '); Alert out "BBBBBBB"