This is my View in Backbone framework:
jQuery(document)ready(function() {
com.company.View = Backbone.View.extend({
initialize : function() {
myCollection.bind('add', this.onSuccess);
},
onSuccess : function(model) {
// do something
this.somethingElse();
},
somethingElse : function() {
// do something else
}
});
});
Now the problem is inside onSuccess function the this object doesn’t belong to the View anymore, it belongs to model. So, when I call this.somethingElse() I got undefined.
How can I successfully call this.somethingElse inside onSuccess?
You want to bind your function to the context of the View object.
In
initialize, do this: