MooTools – Core类 【快捷方式和有用的函数】 »
MooTools Core类 :函数完美解析
MooTools有许多独立的函数,使工作更容易,减少击键。
Mootools中Core.js是Mootools的核心代码,你使用的大部分的函数都位于MooTools的核心/ Core.js 中。
MooTools中包含的一系列常用工具函数,能帮你完成具体的特定种类的任务。
只要在你的脚步中引用这些工具函数,就能完成你需要的特定任务。
查看当前使用的MooTools 版本
一个值,定义你用的mootools的版本。比如当修改别人的网站,别人用了mootools,你不知道它用的mootools是哪个版本,可以这样子输出一下:
1 | MooTools.version |
确定对象的类型: $type
JavaScript是一种一种弱类型的语言,允许大量的表现,但也造成了很多令人头疼的问题。
JavaScript中包含6种数据类型:undefined、null、string、number、boolean和object。其中,前5种是原始数据类型,object是对象类型。
object类型中包括Object、Function、String、Number、Boolean、Array、Regexp、Date、Globel、Math、Error,以及宿主环境提供的object类型。
如果通过javascript中typeof、instanceof、constructor这3种方式来判断数据类型是很麻烦的事。
幸好的是在Mootools Core类中已提供了以上这么多数据类型的判断。
$type :: Core/Core.js
作用:$type函数,检测传入参数的类型
语法:
$type(object) //”string”, “object”, or “array”, etc.
返回值:
| “element” if the object is a DOM element node |
| “textnode” if the object is a DOM text node |
| “whitespace” if the object is a DOM whitespace node |
| “arguments” if the object is an arguments object |
| “object” if the object is an object |
| “array” if the object is an array |
| “string” if the object is a string |
| “number” if the object is a number |
| “boolean” if the object is a Boolean |
| “function” if the object is a function |
| “regexp” if the object is a regular expression |
| “class” if the object is a MooTools class |
| “collection” if the object is a native HTML elements collection, such as childNodes, getElementsByTagName, and so on |
| “window” if the object is the window object |
| “document” if the object is the document object |
| “date” if the object is a date |
| false (Boolean) if the object is not defined(undefined, null, NaN) or is none of the above |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | window.addEvent('domready',function(){ var oBody=document.body;//body元素对象 testType.getType(oBody); }); //$type函数:返回传入对象的类型 var testType={ str_a:'hello', str_b:true, str_c:'', str_d:0, getType:function(str){ alert("object: "+$type(testType)); alert("str: "+$type(str)); alert("str_a: "+$type(this.str_a)); alert("str_b: "+$type(this.str_b)); alert("str_c: "+$type(this.str_c)); alert("str_d: "+$type(this.str_d)); alert("str_c+str_d: "+$type(this.str_c+this.str_d)); } }; |
检测参数值是否已定义:$defined, $chk, and $pick
$defined :: Core/Core.js
往往是在您的代码中,有的时候您需要确定参数值是否已定义或存在。 MooTools给你一些有用的方法,以简化这一基本任务。
作用:$defined函数,检测一个变量是否已定义(也就是说,不是null或undefined)
语法:
$defined(object)
返回值:(boolean) 如果传入对象不为null或undefined,返回true; 否则返回false.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | window.addEvent('domready',function(){ var e=document.getElementById("menu"); myFunction(); myFunction(""); myFunction('hello'); myFunction(e); }); //$defined函数:如果传入的参数为null或undefined,则返回fasle;否则返回true; function myFunction(arg){ if($defined(arg)) alert('The object is defined.'); else alert('The object is null or undefined.'); } |
When you’ll use it: This is just a shortcut for
value == undefined
“Because JavaScript performs type coercion , you can’t just evaluate a value to see if it has a value.”
更快捷的方式:
1 2 3 4 5 6 7 8 | if ("") ... //false if (0) ... //false if (null) ... //false function test(value){ return !!value; }; test(); //No value passed, so it is undefined, //and test() returns false |
由于以上这些例子表明,$defined 函数是一个捷径,但是它取决于这个值是否被设定。
$chk :: Core/Core.js
$chk 检测变量是否定义或者为零;即,检测参数值存在。
作用:检测参数值存在(非null, undefined, false, 或 “”)或为0. 对于接受0值的情况非常有用。
语法:$chk(value)
返回值:(boolean) 如果传入的对象存在或值为0,返回true; 否则返回false.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | window.addEvent('domready',function(){ var e=document.getElementById("menu"); myFunction(false); myFunction(0); myFunction(); myFunction(""); myFunction('hello'); myFunction(e); }); function myFunction(arg){ if($chk(arg)) { alert('The object exists or is 0.'); } else { alert('The object is either null, undefined, false, or ""'); } } |
就像 $defined, $chk 可以帮助您管理 type coercion. $chk 检测变量为null ,undefined, false, 空字符串时会返回false,为零的时候也会返回false
$pick :: Core/Core.js
您可以通过传递多个的参数来挑选您想要的,$pick函数:返回第一个不是undefined或null的元素
‘
如果第一个给出的参数存在,则返回这个参数的值;否则返回给出的第二个参数;以此类推。
作用:返回参数列表中第一个非未定义的项; 如果全部未定义,则返回null
语法: $pick(var1, var2, var3, etc.)
返回值:
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 | window.addEvent('domready',function(){ say(); //显示 "There was no message supplied." say("This is an info message."); //显示 "This is an info message." say(null,"This is the error message.");//"显示This is the error message." say("This message will be ignored.", "This is the error message."); //显示 "This is the error message." }); function say(infoMessage, errorMessage){ alert($pick(errorMessage, infoMessage, 'There was no message supplied.')); } |
$pick 的另一个捷径,以下几个简单的条件判断也能实现$pick的作用:
原例子:
1 2 3 4 5 6 7 8 | function test(variable){ alert($pick(variable, 'no variable defined!')); } test(); /* alerts 'no variable defined!' */ test('hi'); /* alerts 'hi' */ test(false); /* alerts 'false' */ test(''); /* alerts '' */ |
函数的作用是避免你写if…else…判断
如果你想实现上面的功能,在没有上用$pick的情况下,它会看起来就像这样:
1 2 3 4 5 | function test(variable){ if(typeof variable == "undefined" || variable == null) alert('no variable defined'); else alert(variable); } |
What’s important to note here is that zero, an empty string, and false when passed to $pick will return that value. If you were to evaluate the variable itself: if(variable) alert(variable) – your conditional would evaluate those values (zero, “”, the boolean false) and alert that no variable was defined.
It saves you the time of writing out a long if statement.
But it gets even more useful when you need to evaluate numerous things:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function test(variable) { variable = $pick(variable, someOtherVariable, defaultValue); } //typing this out with if/else statements would look like: function test(variable){ if(typeof variable == "undefined" || variable == null){ if(typeof someOtherValue != "undefined" && someOtherValue != null) variable = someOtherValue; else variable = defaultValue; } return variable; } |
工作与对象: $extend, $merge,和 $unlink
本地对象中Hash键值对的设置,在现代的JavaScript中经常应用的,但是在javascript中,没有规范的Hash的实现,因此这种语言也不会有更多的工具来帮助你处理的数据,JavaScript对象不包含任何本地方法或属性,为了方便工作和本地对象,MooTools提供下列核心方法。
$extend :: Core/Core.js
$extend 将第二个参数对象的所有属性复制到第一个参数对象中.如果第一个参数对象中的属性和第二个参数对象中属性有相同的,第一个参数对象的属性将被第二个参数对象覆盖。
作用:将第二个参数对象的所有属性复制到第一个参数对象中.
语法: $extend(object1, object2)
返回值:(object) 复制属性后的第一个参数对象
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | window.addEvent('domready',function(){ var fruits = { apple: 'red', lemon: 'yellow' }; var otherFruits = { apple: 'green', grape: 'purple' }; $extend(fruits, otherFruits); /* fruits has been altered by $extend */ console.log(fruits); /* logs: {apple:'green', lemon: 'yellow', grape: 'purple'} */ }); |
更为复杂的对象,应用$extend
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | window.addEvent('domready',function(){ var names=""; var allObj=$extend(goodNinja, defaultNinja); //遍历对象的属性 for(var name in allObj){ names+=name+"\n"; } alert(names); }); var defaultNinja = { weapons: ['sword', 'star', 'stealth'], equipment: { grapple: 'iron', rope: '40 meters' } }; var goodNinja = { specialAbility: 'warrior spirit', weakness: 'kittens' }; /* $extend(goodNinja, defaultNinja); //Now goodNinja contains the weapons array and the //equipment object */ |
$merge :: Core/Core.js
合并一组对象生成新对象
作用:
语法: var merged = $merge(obj1, obj2[, obj3[, ...]]);
返回值: 1. (objects) 任意数量的对象
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | window.addEvent('domready',function(){ var fruits = { apple: 'red', lemon: 'yellow' }; var otherFruits = { apple: 'green', grape: 'purple' }; var newFruits = $merge(fruits, otherFruits); console.log('newFruits: ', newFruits); /* fruits has NOT been altered by $merge */ console.log('unaltered fruits: ', fruits); /* logs: {apple:'red', lemon: 'yellow'} */ fruits = $merge(fruits, otherFruits); /* fruits HAS been altered by setting the result using = */ console.log('fruits altered: ', fruits); /* logs: {apple:'green', lemon: 'yellow', grape: 'purple'} */ }); |
注意:
console.log();
console.log();
//注console,只能在firefox且,安装了firebug时才可以用,会在console中输出结果
比较$merge和$extend
基本功能一样,用于合并对象的属性,
区别在于$extend会修改原来的对象(第一个参数的那个) ,
而$extend是返回新对象,再一个就是$extend接收两个参数,$merge没有限制。
1 2 3 4 5 6 7 8 9 10 11 12 13 | var fruits = { apple: 'red', lemon: 'yellow' }; var otherFruits = { apple: 'green', grape: 'purple' }; $extend(fruits, otherFruits); /* fruits has been altered by $extend */ console.log(fruits); /* logs: {apple:'green', lemon: 'yellow', grape: 'purple'} */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | window.addEvent('domready',function(){ var fruits = { apple: 'red', lemon: 'yellow' }; var otherFruits = { apple: 'green', grape: 'purple' }; var yetMoreFruits = { apple: 'yellow', orange: 'orange' }; var newFruits = $merge(fruits, otherFruits, yetMoreFruits); console.log(newFruits); /* logs: {apple:'yellow', lemon: 'yellow', grape: 'purple', orange: 'orange'} */ }); |
注意:
console.log();
console.log();
//注console,只能在firefox且,安装了firebug时才可以用,会在console中输出结果
$merge recurses
重要的是要注意$merged是recursive,就是说如果对象的属性还是对象的时候,$merge会拷贝那些属性,
这样子与原来的对象没有关系了。
而$extend仅仅是引用,修改原来的对象的属性(属性是对象的时候).
If you use $extend to merge two objects together and the second object contains members that are also objects, you will create a link between the two:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | var fruits = { apple: 'red', lemon: 'yellow' }; var detailedFruits = { apple: { goldenDelicious: 'yellow', pinkLady: 'red', sour:'green' } }; $extend(fruits, detailedFruits); console.dir(fruits); /* logs {apple:{goldenDelicious:'yellow', pinkLady:'red', sour: 'green'}, lemon: 'yellow'} */ /* changing apple in one changes it in both */ detailedFruits.apple.pinkLady = 'pink'; console.dir(fruits); /* logs {apple:{goldenDelicious:'yellow', pinkLady:'pink', sour: 'green'}, lemon: 'yellow'} */ The link between fruits and detailedFruits shouldn't exist, but it does because apple is an object. |
$merge, though, will recurse into detailedFruits.apple copying the values of each of its members so that this link does not exist.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | var fruits = { apple: 'red', lemon: 'yellow' }; var detailedFruits = { apple: { goldenDelicious: 'yellow', pinkLady: 'red', sour:'green' } }; fruits = $merge(fruits, detailedFruits); console.dir(fruits); /* logs {apple:{goldenDelicious:'yellow', pinkLady:'red', sour: 'green'}, lemon: 'yellow'} */ /* now changes to one object do not affect the other */ detailedFruits.apple.pinkLady = 'pink'; console.dir(fruits); /* logs {apple:{goldenDelicious:'yellow', pinkLady:'red', sour: 'green'}, lemon: 'yellow'} */ |
Most of the time you won’t use $merge. It’s used within MooTools for certain types of inheritance and whenever you need to combine objects that contain objects, but it’s far less efficient than $extend. If you understand the purpose of each and use them appropriately you shouldn’t have any trouble.
$unlink :: Core/Core.js
$unlink 将返回一个副本,是一个对象或数组。其中不包含任何原始的链接。(即,消除了原始的引用,它不会污染到原始的对象)
作用:
语法:
$unlink(array)
$unlink(object)
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 | var fruits={}; var otherFruits={}; fruits={ apple:['red', 'yellow', 'green'], grape:'purple' }; otherFruits=$unlink(fruits); //otherFruits=fruits;//如果没有使用$unlink创建副本的话,对象的属性会被修改 otherFruits.apple=['red','green']; alert(fruits.apple); |
通过例子我们详细的讨论了$merge,$extend和$unlink,如果还不能完全理解它们的话,那就自己动手多写一些例子来测试它们的,以便更深入的理解它们。
枚举助手和快捷函数: $arguments, $each, $splat, $A, and $H
$each :: Core/Core.js
迭代数组(包括非常规数组,如由内建的getElementsByTagName方法返回的集合对象, arguments对象, 或Ojbect对象)
作用:用于迭代数组,包括本身不是数组,但可以迭代的对象,如函数的参数对象arguments.对于迭代真正的数组$each(),与array.each()
是一样的,对于本身不是数组,但可以迭代的对象,两者是有区别的
语法:
$each(arguments, function(value, [index or key]){
alert(value);
}, bin
Example:
对于不是真正的数组,用array.each时候要加上$A()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function test(){ $each(arguments,function(item,key){ alert(item); }) } function test1(){ $A(arguments).each(function(item){ alert(item) }); } test1('a','b','c') test('a','b','c') |
更多的例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | //Simple example with function referencing each value $each([1,2,3], function(value){ alert(value); //Alerts 1, 2, 3 }); //Same concept but the function also references //the index of each value $each([1,2,3], function(value, index){ alert('the value at index ' + index + ' is ' + value); //Alerts //"the value at index 0 is 1" //"the value at index 1 is 2" //"the value at index 2 is 3" }); //This example illustrates binding var example = { say: function(msg) { alert(msg);}, count: function(){ $each([1,2,3], function(number) { this.say(number); }, this); //Here's the important part! } }; //This example illustrates iterating over an object $each({apple: 'red', lemon: 'yellow'},function (value, key) { alert(key + 's are ' + value); //Alerts // "apples are red" // "lemons are yellow" }, this); //The binding of 'this' is optional |
注意:
$each是另一种方式来迭代数组或对象。这是一个它取代的这些语法:
//Array loop:
1 2 | for(var i = 0; i < array.length; i++){ alert(array[i]) } |
//Object loop:
1 2 | for(key in object) { alert(object[key]) } |
更重要的是更重要的是,$each是一个非常实用的方法,适合于数组和对象。
实战:
以‘我的导航条’为例,再使用一下$each,来遍历导航条元素对象。
//HTML CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <div id="menu"> <h1>我的导航条</h1> <ul id="nav"> <li><a href="#">HOME</a></li> <li><a href="#">(X)Html / Css</a></li> <li><a href="#">Ajax / RIA</a></li> <li><a href="#">GoF</a></li> <li><a href="#">JavaScript</a></li> <li><a href="#">JavaWeb</a></li> <li><a href="#">jQuery</a></li> <li><a href="#">MooTools</a></li> <li><a href="#">Python</a></li> <li><a href="#">Resources</a></li> </ul> </div> |
//JAVASCRIPT CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | window.addEvent('domready',function(){ test_nav$(); test_nav$$(); test_nav(); }); //方法一 function test_nav$(){ var navElements=$('nav').getElements('li');//每一个元素的所有子元素的集合 $each(navElements,function(item,key){ alert(key+" = "+item.innerHTML); }); } //方法二 function test_nav$$(){ var navElements=$$('#nav li');//返回id为'nav'的元素下的所有li元素对象 $each(navElements,function(item,index){ alert(index+" = "+item.innerHTML); }); } //方法三 function test_nav(){ var navElements=document.getElementById("nav").getElementsByTagName("li"); $each(navElements,function(item,index){ alert(index+" = "+item.innerHTML); }); } |
$arguments :: Core/Core.js
创建一个可返回传入参数的特定项的函数
语法: var argument = $arguments(i);
返回值:(function) 可返回特定项参数的函数
Example:
1 2 3 | var secondArgument = $arguments(1); //创建一个总返回传入参数的第二个参数的函数 alert(secondArgument('a','b','c')); //显示 "b" |
$splat :: Core/Core.js
$splat图标转换参数传递到一个数组如果尚未一个数组。这是非常有用的当你希望有一个方法,接受一个论点,即不是一个单一的对象或一个数组的。
作用:把传入的参数包装成一个数组
语法: $splat(object)
返回值:(array) //如果传入的参数是个数组,那么返回该数组; 否则,返回一个包含传入参数的数组
Example:
1 2 3 | $splat('hello'); //返回 ['hello'] $splat(['a', 'b', 'c']); //原样返回 ['a', 'b', 'c'] |
例子2:
1 2 3 4 5 6 7 | function myFavoriteThings(things){ alert("I like " + $splat(things).join(" and ")); }; myFavoriteThings("cookies"); /*I like cookies*/ myFavoriteThings(["cookies", "cake", "ice cream"]); /*I like cookies and cake and ice cream*/ |
$A :: Core/Core.js
创建一个数组的拷贝.
可以将数组的迭代功能添加到具备可迭代特性的对象中, 如:DOM节点集合或arguments对象
作用:这些方法适用于任何iterable对象
语法: var copiedArray = $A(iterable);
返回值:(array) 新生成的数组
Example:
1 2 3 4 5 6 7 | function myFunction(){ $A(arguments).each(function(argument, index){ alert(argument); }); }; myFunction("One", "Two", "Three"); //依次显示 "One", "Two", "Three" |
例子2:
1 2 3 4 5 6 7 8 9 10 11 12 13 | var ninja = { weapons: [], equip: function(){ $A(arguments).each(function(weapon){ ninja.weapons.push(weapon); }); } }; ninja.equip("sword", "star", "smoke"); $each(ninja.weapons,function(ietm,index){ alert(index+" = "+ietm) }); |
$H :: Core/Core.js
新建Hash实例(new Hash)的快捷函数
作用:Just a short hand for new Hash();
语法: $H(object)
Example:
1 2 | var fooHash = $H({foo: 'bar'}); |
其他快捷函数: $clear, $empty, $lambda, $random, $time, $try
除了在本章的前面介绍了iteration 和 inspection shortcuts 的实用函数,MooTools还提供了其它的core tricks,比使用JavaScript中一些方法更方便一些。
除了这些 tand-alone functions(和其他一些在library里),几乎所有的其他functions都是针对MooTools中的native objects(如Array或String)或MooTools classes(如effects)。
$clear :: Core/Core.js
清除定时器(Timeout或Interval). 通常配合Function:delay和Function:periodical方法使用.
作用:clears the passed in timeout
语法: $clear(timer)
返回值: (false) 返回null
Example:
1 2 | var oneSec = setTimeout(function(){alert('二秒钟以后...')}, 2000); $clear(oneSec); //nevermind |
$empty :: Core/Core.js
一个什么事情都不做的空函数. 典型应用: 事件监听器的占位方法.
语法: var callback = $empty;
返回值: 空函数
Example:
1 2 3 4 5 6 7 8 9 10 11 | var ninja = { afterAttack: $empty, attack: function(enemy) { enemy.isAlive = false; ninja.afterAttack(); } }; //Later ninja.afterAttack = function(){ ninja.weep(); }; |
$lambda :: Core/Core.js
对传入的参数进行函数封装.
即,如果传入参数为一个function,则原样返回该function;
作用:返回一个函数,函数的返回值,就是传给$lambda的参数
语法: var returnTrue = $lambda(true);
返回值: (function) 一个能返回给定对象的函数
Example:
1 2 3 4 5 | $('myLink').addEvent('click', function(){ return false; //禁止myLink的点击 }); //等价于: $('myLink').addEvent('click', $lambda(false)); //同样的事情! |
如果为其他对象,则返回一个新创建的function, 该function不做其他任何事,仅仅是返回原来这个对象.
1 2 3 4 5 6 7 8 9 10 11 | var test = function(item){ return $lambda(item)(); //应用了匿名函数 //If item is not a function, //lambda creates a function //then we return the result of that function /* return $type($lambda(item)); //返回类型为function */ }; |
注意;关于javascript的匿名函数请看:
javascript的匿名函数(收藏)
$random :: Core/Core.js
返回一个随机数字
作用:返回指定区间内的一个随机整数
语法: var random = $random(min, max);
返回值:(number) 给出区间范围内的一个随机整数
Example:
1 | alert($random(5, 20)); //显示: 5~20之间的一个随机整数 |
$time :: Core/Core.js
返回当前时间戳,是毫秒数,没多大作用,内部用(tween效果的时间间隔处理等)。
作用:A shortcut for new Date.getTime();
语法: var time = $time();
返回值:(number) – 当前时间戳
Example:
1 | $time(); //the current time value |
$try :: Core/Core.js
尝试执行给出的一组函数, 并返回第一个执行成功的函数的返回值;
如果一个都没执行成功,则返回null;
作用:
语法: $try (fn, fn, fn, etc.);
返回值:
* (mixed) 返回第一个执行成功的函数的返回值
* (null) 如果一个都没执行成功,则返回null
Example:
1 2 3 4 5 6 7 8 | $try(function(){ console.log(foo.bar); /*this doesn't exist, throws an error*/ }, function(){ var msg = null; console.log(msg.length); /*null has no properties, throws an error*/ }, function(){ console.log("I don't contain any errors"); }); |
例:想知道MooTools的版本号,但不知道mootools的大小写
1 2 3 4 5 6 7 8 9 10 | var name=$try( function(){ return mootools.version }, function(){ return Mootools.version }, function(){ return MooTools.version }); |
里边的第一个函数抛出错误,因为没有mootools这个对象(javasript区分大小定),只有第三个不抛出错,所以返回其值,如果三个函数都有错
那么返回null
Browser: Information About the Client
Browser是一个Hash实例. 该对象储存了一系列用于浏览器和平台检测的属性
浏览器特性相关:
- Browser.Features.xpath – (boolean) 当前浏览器是否支持XPath进行DOM查询
- Browser.Features.xhr – (boolean) 当前浏览器是否支持原生的XMLHTTP对象
浏览器渲染引擎相关:
- Browser.Engine.trident – (boolean) 当前浏览器是否为Internet Explorer(版本不限)
- Browser.Engine.trident4 – (boolean) 当前浏览器是否为Internet Explorer 6
- Browser.Engine.trident5 – (boolean) 当前浏览器是否为Internet Explorer 7
- Browser.Engine.gecko – (boolean) 当前浏览器是否为Mozilla/Gecko
- Browser.Engine.webkit – (boolean) 当前浏览器是否为Safari/Konqueror
- Browser.Engine.webkit419 – (boolean) 当前浏览器是否为Safari2/WebKit(419之前的版本)
- Browser.Engine.webkit420 – (boolean) 当前浏览器是否为Safari3 (WebKit SVN Build)/WebKit(419之后的版本)
- Browser.Engine.presto – (boolean) 当前浏览器是否为Opera
- Browser.Engine.presto925 – (boolean) 当前浏览器是否为Opera(9.25或之前的版本)
- Browser.Engine.presto950 – (boolean) 当前浏览器是否为Opera(主版本或9.50之后的版本)
- Browser.Engine.name – (string) 当前浏览器使用的渲染引擎的名称
- Browser.Plugins.Flash.version – (number) 当前浏览器安装的flash插件的主版本号
- Browser.Plugins.Flash.build – (number) 当前浏览器安装的flash插件的子版本号
操作系统平台:
- Browser.Platform.mac – (boolean) 当前操作系统是否为Mac
- Browser.Platform.win – (boolean) 当前操作系统是否为Windows
- Browser.Platform.linux – (boolean) 当前操作系统是否为Linux
- Browser.Platform.ipod – (boolean) 当前操作系统是否为iPod Touch / iPhone
- Browser.Platform.other – (boolean) 当前操作系统即不是Mac, 也不是Windows或Linux
- Browser.Platform.name – (string) 当前操作系统的名称
参考文献:
- MooTools 1.2 中文参考文档
- Apress.MooTools.Essentials.Aug.2008
- A MooTools Tutorial :: The “Mootorial“