MooTools is a good JavaScript framework, it is simple, modular, easy to use, developers can quickly start to write scalable, compatible with good JavaScript code. I used this for two days, feeling and prototype usage is exactly the same, but the function seems to strengthen, have a lot of effect, drag and drop. And it's object-oriented, inheritance more intuitive than prototype, so I began to learn this framework.
First look at the basic usage of mootools, and more detailed explanations can be found on the official website.
1.? If we're going to write a animal class, we can write this:
var New Class ({
function(name)
{This
. Name = name;
}
});
It's a lot like prototype's class.create, but I think it's more handy to use this. The variable defined by this is a member of a class that can be used arbitrarily in a class function.
If we're going to add new methods to the animal class, it's easy to just call the Extend method:
Animal.extend ({
function()
{return this
": no Sound";
}
});
2. Element operation. MooTools uses the element class to encapsulate HTML elements, adding a number of common ways to look at the following code:
var New Element (' div ', {
' styles ': {'
width ''200px ',
' height ' ) ' 300px ',
' border '1px solid red '
,
' events ': {
' click ' function ()
{
alert (' test ');}}
). Inject (document.body);
is not very clear, the elements of the type, style, event, location is very clear expression, people at a glance and the amount of code is very small.