最近在学习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”?
麻烦懂的解答一下 感激不尽
看到第一个例子就有看不懂的地方
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”?
麻烦懂的解答一下 感激不尽