Sheesh, issues that recently seem to be focusing more on the internal functions of mootools.
I will answer as far as I know, since I am not the main developer.
Type in MooTools is quite similar to a class (in fact, the constructor of the class itself is a type ), but it focuses more on data / values โโand Value Types. It is also designed to extend the native types defined by the ECMA specification and makes them more flexible.
I think it makes no sense to talk about data types in general ( String , Number , Array , Object , etc.). Why do they need to be expanded? Well, for starters, Duct Typing is a little freaky in js. typeof {}; // object typeof {}; // object , typeof []; // object typeof []; // object , typeof new Date(); // object typeof new Date(); // object , etc. - not the most useful, even if, since all types are inherited from the object and logically combine them, this will not help you write code.
So, in the context of js objects, they are created from constructor objects ...
Which type does not replace constructor functions, but modifies an existing constructor by adding new methods or properties to it.
eg. new Type('Array', Array);
This will turn the built-in Array constructor into an object of type type. You do not need to save the result or anything else - this is a one-time operation that changes the original and leaves it open for manipulation.
typeOf(Array); // type
So what is different? Well, for starters, typeOf([]) can now actually tell us that it is actually an Array . And what actually happens here: object.extend(Type); magic bit. It will copy to the target all the properties defined in the Type object, you can see them here:
https://github.com/mootools/mootools-core/blob/master/Source/Core/Core.js#L211-232
So, right away your newly created type gets all the important implement and extend methods.
More advanced, create a new type based on the built-in array constructor:
var foo = new Type('foo', Array), a = new foo();
But what if we need a custom type? Is one of them magical and special? No problem, because argument 2 can indeed be a (anonymous) function.
var Awesome = new Type('awesome', function(name, surname) { // console.log('IR teh construct0r!'); this.name = name; this.surname = surname; }); // extend it a little. Awesome.implement({ getName: function() { return this.name; }, getSurname: function() { return this.surname; } }); var Dimitar = new Awesome('dimitar', 'christoff'); console.log(typeOf(Dimitar)); // awesome console.log(Dimitar.getName()); // dimitar
In another example, check out DOMEvent. It takes the above and turns it into a faster, more compact type of object. https://github.com/mootools/mootools-core/blob/master/Source/Types/DOMEvent.js#L21
So why is this not a class? Because classes are more expensive and events happen all the time.
Hope this helps you. for a more detailed explanation, ask on the mailing list and hope for the best, maybe the main developer will have time, because this is not your standard question about how to get a question about the operation of the accordion ...