I have the following code in my Backbone app, Is there a way to bind “this” to the callbacks rather than having to assign “$this” all the time?
addItem: function()
{
var $this = this;
(new Project()).save({name:$('#project_name').val()},{
success:function(model, response)
{
$this.collection.add(model);
},
error: function()
{
console.log('wtf');
}
});
}
You have Underscore available so you could
_.bindmanually:Or just use methods for the callbacks and
_.bindor_.bindAllthose: