
























这是一个创建于 4916 天前的主题,其中的信息可能已经有所发展或是发生改变。
最近在学习backbone.js
看到第一个例子就有看不懂的地方
http://arturadib.com/hello-backbonejs/docs/1.html
(function($){
var ListView = Backbone.View.extend({
...
initialize: function(){
_.bindAll(this, 'render'); // fixes loss of context for 'this' within methods
this.render(); // not all views are self-rendering. This one is.
},
...
});
...
})(jQuery);
请问:
Q1: 为什么用 (function($){})(jQuery);而不用 (function(){})();?
Q2: _.bindAll(this, 'render') 是干啥的? 为什么可以“fixes loss of context for 'this' within methods”?
麻烦懂的解答一下 感激不尽
1 zythum 2012 年 12 月 28 日Q1. (function(){ 这样就应该能理解了。 2. 就是把这些自定义事件绑到this上 |
2 ljbha007 2012 年 12 月 28 日@zythum |
3 zythum 2012 年 12 月 28 日Q2. 其实解释改下this的上下文。 _.bindAll(a,'click'); |
5 FuryBean 2012 年 12 月 28 日Q1: 提供使用其他选择器的可能,比如zepto.js Q2:_.bindAll的文档看这里:http://underscorejs.org/#bindAll |
10 jinwyp 2012 年 12 月 28 日_.bindall 现在不用了都用 model.on 了 网站的教程比较老 看这个吧 |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。