mootools官方网站:www.mootools.net
mootools是一个简洁化,模块化,面向对象的javascript框架.它能够帮你更快更简单的编写可扩展和兼容性强的javascript代码.
mootools 从prototype中汲取了许多有益的设计理念,语法也和其及其相似.但是它提供的功能要比 prototype 强大的多
整体设计也比prototype相对完善,比如增加了动画特效,拖拽操作等.
先推荐一个网站:http://clientside.cnet.com/wiki/mootorial/#a-mootools-tutorial-the-mootorial
学习mootools挺不错
$chk
如果传入的对象存在或有值就返回true,否则返回false
$chk([]); //true
$chk(0); //true
$chk('');//false
$chk(null); //false
$chk(false); //false
$defined
如果传入的对象为null或者undefined,则返回false,否则返回true
$defined('');//true
$defined(false); //true
var x = null;
alert($defined(x)); /* false */
function example(value){
alert($defined(value));
}
example();/*false*/
清理Timeout或者Interval.
var oneSec = setTimeout(function(){alert('one second later...')}, 1000); $clear(oneSec); //nevermind
可用来对非常规数组进行迭代.
$each(["one", "two", "three"],function(number){ alert(number); });
$each({apple:'red',lemon:'yellow',lime:'green'}, function(value, key){ alert(key+"s are "+value); });
<BODY> <a id='myLink' href="http://www.google.com">谷歌</a> <script> $('myLink').addEvent('click', function(){ return false; //stop the browser from following the link }); $('myLink').addEvent('click', $lambda(false)); </script> </BODY>
其中上面两种颜色的代码所实现的 的功能是一样的
$extend是将第二个参数的所有属性复制到第一个对象
<script> var fruits = { apple: 'red', lemon: 'yellow' }; var otherFruits = { apple: 'green', grape: 'purple' }; $extend(fruits, otherFruits); /* fruits has been altered by $extend */ $each(fruits,function(value,key){ alert(key+"s are "+value); }); /* alert: {apple:'green', lemon: 'yellow', grape: 'purple'}*/ </script>
$merge 把几个对象进行合并,合并时递归的,即对象中如果有子对象,则子对象也会进行合并.(对象中同名属性会被这一
系列对象中最后一个拥有该属性的对象的值替代)
var fruits = { apple: 'red', lemon: 'yellow' }; var otherFruits = { apple: 'green', grape: 'purple' }; var newFruits = $merge(fruits, otherFruits); $each(newFruits,function(value,key){ alert(key+"s are "+value); }); /* fruits has NOT been altered by $merge */ $each(fruits,function(value,key){ alert(key+"s are "+value); }); /* logs: {apple:'red', lemon: 'yellow'} */ fruits = $merge(fruits, otherFruits); /* fruits HAS been altered by setting the result using = */ $each(fruits,function(value,key){ alert(key+"s are "+value); }); /* logs: {apple:'green', lemon: 'yellow', grape: 'purple'} */
$extend和$merge方法的比较:
1 $merge方法允许有任意多个参数,extend只允许有2个.
2 $extend方法可能改变第一个参数的属性,$merge会产生一个新的对象而不会改变参数中的对象.