javascript - Calling a method from inside a view without using "this" keyword? -
my backbone code seems have crazy number of this.methodcall() type of invocations , i'd love able drop this, , call methodcall() directly inside view.
see below code:
app.main = backbone.view.extend({ el: '#main-div', // how call function without invoking "this"? setpagecookies: function () { console.log('setting page cookies called!'); }, initialize: function () { // saw online possible solution, seems affect scope of "this" _.bindall(this, 'setpagecookies'); // works: this.setpagecookies(); // however, i'd able call instead: setpagecookies(); } });
firstly - this.setpagecookies() , setpagecookies() have drastically different meanings.
the way achieve calling setpagecookies() without this make setpagecookies function declaration:
function setpagecookies() { } backbone.view.extend({ setpagecookies: setpagecookies, initialize: function() { setpagecookies() } }); however, can't use this instead of setpagecookies - unless use bind, or unless write complicated wrapper around setpagecookies: setpagecookies takes this value , passes first argument.. or something. makes me ask - why want achieve this?
Comments
Post a Comment