为什么这个日志记录为窗口而不是 Backbone 对象?
App.Models.Site = Backbone.Model.extend({
url: 'assets/json/app.json',
initialize: function(){
this.fetch({success:this.success});
},
success: function(){
console.log('success', this.attributes); // log's: success undefined
console.log(this); // window
}
});
最佳答案
因为该函数由 jQuery(或您使用的任何 DOM 库)ajax
函数调用。
使用 this.fetch({success:_.bind(this.success, this)});
关于javascript - 窗口的主干范围而不是这个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14936869/