
1 zythum 2012-12-28 16:55:49 +08:00 Q1. 比如 (function($){ setTimeout(function(){ alert($); },200) })(JQuery); JQuery = null; (function(){ setTimeout(function(){ alert(jQuery); },200) })(); jQuery = null; 这样就应该能理解了。 2. 就是把这些自定义事件绑到this上 |
2 ljbha007 OP @zythum 谢谢 第一个我明白了 第二个“把这些自定义事件绑到this上”是什么意思?这样的绑定又是怎么防止"loss of context for 'this' within methods"的呢? |
3 zythum 2012-12-28 17:03:17 +08:00 Q2. 其实解释改下this的上下文。 比如 var a = { click: function(){alert(this)} } a.click(); => alert window _.bindAll(a,'click'); DOM.bind('click', a.click) 点击 => alert DOM |
5 FuryBean 2012-12-28 17:07:33 +08:00 Q1: 提供使用其他选择器的可能,比如zepto.js Q2:_.bindAll的文档看这里:http://underscorejs.org/#bindAll 如果了解bind,看_.bind的说明: Bind a function to an object, meaning that whenever the function is called, the value of this will be the object. Optionally, bind arguments to the function to pre-fill them, also known as partial application. |
8 ljbha007 OP @zythum 不过我最后搞懂那个_.bindAll的意思和原理了 貌似是利用.apply或者.call方法来注入一个this对象 |
10 jinwyp 2012-12-28 22:50:48 +08:00 _.bindall 现在不用了都用 model.on 了 网站的教程比较老 看这个吧 |