超方便!mootool function之bind this!

mootool这个类oo型的S框架果然强大!其中的function类有一个方法叫bind,这东西太方便了!怎样方便,请看以下代码:
HTML代码:

<div id="element">mootool要变我颜色了!</div>

JS代码:

var e=$('element');
function ChangeColor(){
   this.setStyle('background','red');
}
var ChangeColorBind=ChangeColor.bind(e);//这样ChangeColor函数里面的this就被e元素替换了!
ChangeColorBind();

也许这里你还没看见这个有多方便方便,但是涉及到嵌套函数的时候你就知道它有多强大了!

2 Responses to 超方便!mootool function之bind this! »

  1. LD 评论 2008-12-01 23:11

    学习,不过偶用jquery,看来js的框架都不错哦; 偶还有童鞋学ext的

    回复

    joe 回复 十二月 2nd, 2008 at 09:16

    mootool真的不错

    回复

Leave a Reply

Email address is not published

You should say a Chinese word to pass spam check. If you can not input Chinese, just copy 你好 and paste them into comment text box.