我的骨干代码似乎有一个疯狂的this.methodCall()
类型的调用,我很乐意放弃this
,只需直接从内部调用methodCall()
视图。
见下面的代码:
app.Main = Backbone.View.extend({
el: '#main-div',
// how do I call this function without invoking "this"?
setPageCookies: function () {
console.log('setting page cookies called!');
},
initialize: function () {
// saw this online as a possible solution, but only seems to affect the scope of "this"
_.bindAll(this, 'setPageCookies');
// this works:
this.setPageCookies();
// HOWEVER, I'd like to be able to call it like this instead:
setPageCookies();
}
});