MooTools framework "Two"-core: Method Complete Analysis

Source: Internet
Author: User

Note: The core libraries in the cores class are the moo.js and utility.js,moo.js that contain the underlying classes that implement OO, and Utility.js provides the most commonly used tool-function encapsulation.

---------------------------Moo.js-------------------------------------

1.mootools constructs the object using the following form:

var Cat  = new Class ({
Initialize:function (name) {
THIS.name = name;
}
});
var cat = new Cat (' Kitty ');
alert (cat.name);

2.Class to inherit, MooTools is doing this:

var Animal = new Class ({
Initialize:function (name) {
THIS.name = name;
}
});
var Cat = Animal.extend ({
Initialize:function (name,age) {
This.parent (name); Call the animal Initialize method
This.age = age;
}
});

The 3.class.implement method extends the class that has already been defined

(For example, add a method), as follows:

var person = new Class ({
Initialize:function (name) {
THIS.name = name;
}
});
Person.implement ({
Initialize:function (name,age) {
THIS.name = name;
This.age = age;
},
Myaction:function () {
Alert (this.name+ '-' +this.age);
}
});
var p = new Person (' zarknight ', 24);
P.myaction ();

MooTools extends a extend method to object, which has two parameters that replicate all the properties of the second parameter object to the first parameter object, and the same name overrides the corresponding property in the second argument:

var Firstob = {
' Name ': ' John ',
' LastName ': ' Doe '
};
var Secondob = {
' Age ': ' 20 ',
' Sex ': ' Male ',
' LastName ': ' Dorian '
};
Object.extend (Firstob, Secondob);
Firstob will become:
{
' Name ': ' John ',
' LastName ': ' Dorian ',
' Age ': ' 20 ',
' Sex ': ' Male '
};

---------------------------Moo.js-------------------------------------

4. $type

Function: Basically an extension of the TypeOf, returning the type of the input parameter

Example:

var x=$type("abcdefg");

return value:

'element'-DOM
'textnode'-DOM文本节点
'whitespace'-DOM空白节点
'array'-数组
'object'-对象
'string'-字符串
 'number'-数字
 'boolean'-布尔型
'function'-函数

false-if it is undefined or not the type listed above

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.