I would like to do pass a function to backbone’s success callback like this
this.model.fetch({
success: this.setup
});
However, that won’t work I end up having to pass the whole environment and wrap inside a function like that:
var that = this;
this.model.fetch({
success: function(){
that.setup();
}
});
Why can’t I do this? Even if I bind the setup function to it’s parent like so _.bind( this.setup, this );, it still won’t use the proper this (its’ parent). But only if its’ not wrapped in a function…
_.bindreturns a function bound to an object, it does not modify the original function (basically it creates the wrapped function you wrote).However, you could pass this bound function as a callback
or use
_.bindAllwhich does modify the object to use bound functions: