在不使用“this”关键字的情况下从视图内部调用方法?

时间:2015-07-14 14:22:52

标签: javascript backbone.js scope

我的骨干代码似乎有一个疯狂的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();

    }

});

0 个答案:

没有答案