mootool文檔(core)

Mootools - Type:Core

Core包含了Mootools的常用功能

Function: typeOf

 返回對象的類型

語法:
 typeOf(obj)
參數:
 1.obj-(對象)待檢查的對象

返回值
'element' - (string) 如果對象是DOM元素節點
'elements' - (string) 如果對象是元素的實例
'textnode' - (string) 如果對象是DOM文本節點
'whitespace' - (string) 如果對象是一個DOM空白節點
'arguments' - (string) 如果對象是一個參數對象。.
'array' - (string) 如果對象是一個數組.
'object' - (string) 如果對象是一個對象.
'string' - (string) 如果對象是字符串.
'number' - (string) 如果對象是數字.
'date' - (string) 如果對象是日期.
'boolean' - (string) 如果對象是布爾值.
'function' - (string) 如果對象是一個函數.
'regexp' - (string) 如果對象是正則表達式.
'class' - (string) 如果對象是一個類 (新創建的或者其他類擴展的類).
'collection' - (string) 如果對象是一個HTML元素的集合,像子節點或者使用getElementsByTagName獲取的
'window' - (string) 如果對象是 window 對象.
'document' - (string) 如果對象是document 對象.
'domevent' - (string) 如果對象是事件.
'null' - (string) 如果對象是 undefined, null, NaN 或非以上列出的.


示例:

var myString = 'hello';
typeOf(myString); // returns "string"



注意:
這個方法等同於Mootools1.2中的$type方法,異常undefined和null值返回字符串'null',而不是false

 

Function: instanceOf
檢查對象是否爲一個特定類型的實例

語法:
instanceOf(item, object)

參數:
item - (mixed) 檢查的對象.
object - (mixed) 用於比較的類型.
返回值:
(boolean) 如果 item 是object的實例返回true否則返回false
示例:

var foo = [];
instanceOf(foo, Array) // returns true
instanceOf(foo, String) // returns false
 
var myClass = new Class();
var bar = new myClass();
instanceOf(bar, myClass) // returns true


類型
MooTools 擴展了原生類型, 像 string, array 和 number.

MooTools使用的類型:

String
Array
Number
Function
RegExp
Date
Boolean

MooTools自定義的類型:
Element
Elements
Event

 

Type method: implement
在類型的原型(prototype)上實現新的方法


語法:
myType.implement(name, method);

myType.implement(methods);

參數:
name - (string) 方法名.
method - (function) 方法的功能(函數).
或者
methods - (object) 一個鍵值對對象(key-value). 鍵(key)對應方法名, 值(value)對應方法的功能(函數).
返回值:
(object) The type.
示例:

Array.implement('limitTop', function(top){
    for (var i = 0, l = this.length; i < l; i++){
        if (this[i] > top) this[i] = top;
    }
    return this;
});
 
[1, 2, 3, 4, 5, 6].limitTop(4); // returns [1, 2, 3, 4, 4, 4]


 

它也可以傳遞一個對象方法:

String.implement({
    repeat: function(times){
        var string = '';
        while (times--) string += this;
        return string;
    },
    ftw: function(){
        return this + ' FTW!';
    }
});
 
'moo! '.repeat(3); // returns "moo! moo! moo! "
'MooTools'.ftw(); // returns "MooTools FTW!"
('MooTools'.ftw() + ' ').repeat(2); // returns "MooTools FTW! MooTools FTW! "



Type method: extend
添加一個或多個功能到類型,屬於靜態函數

語法:
myType.extend(name, method);

myType.extend(methods);
參數:
name - (string) The method name.
method - (function) The method function.

methods - (object) An object with key-value pairs. The key is the method name, the value is the method function.
返回值:
(object) The type.
示例:

RegExp.extend('from', function(regexp, flags){
    return new RegExp(regexp, flags);
});
 
Number.extend('parseCurrency', function(currency){
    // takes a string and transforms it into a number to
    // do certain calculations
});


Generics
作爲通用功能,可用於大多數類型的方法。這些都是現有的JavaScript方法,MooTools增加的方法,或你實現自己的方法。

示例:

var everyArgBiggerThanTwo = function(){
    // Instead of this
    return Array.prototype.every.call(arguments, someFunction);
    // you can use
    return Array.every(arguments, someFunction);
};


 

This is useful if methods of a certain type should be used as function of another type. As the example above, it is used for the Arguments type, which is not a real array, so arguments.every(fn) would not work. However, Array.every(arguments, fn) does work in MooTools.
語法:
Type.methodName(thisArg[, arg1, arg2, ...]);
參數:
thisArg - (mixed) This is the subject, which is usually thisArg.method([arg1, arg2, ...]);.
arg1, arg2, ... - (mixed) Additional arguments which will be passed as method arguments.
返回值:
(mixed) Anything the method usually returns.

 

原文:http://mootools.net/docs/core/Core/Core

打算翻譯mootools文檔,翻譯起來感覺有的不知道怎麼表達出來合適,很多未翻譯,希望大家指正或一起翻譯或提供翻譯

 不再翻譯,網上已有Mootools愛好者羣(16648471)的翻譯:http://www.51mootools.com/docs/core/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章