Skip to content

Instantly share code, notes, and snippets.

@c0debreaker
Last active September 4, 2015 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c0debreaker/d0c2064e5e1eef65fece to your computer and use it in GitHub Desktop.
Save c0debreaker/d0c2064e5e1eef65fece to your computer and use it in GitHub Desktop.
backbonejs fetch prototype
// fetch.js
fetch: function fetch(options) {
var deferred = $.Deferred();
Backbone.Model.prototype.fetch.call(this, _.extend({
deferred: deferred
},
options));
return deferred;
},
// fetchItem.js
fetchItem: function fetchItem(itemSummary) {
// this fetch is the code above on line 3
this.item.fetch().done(_.bind(function() {
this.renderItem(this.item);
},this))
.fail(function(error){
// when GET fails like network issues, this won't show unlike native $.ajax fail where it will show the error
console.log(error);
});
},
or
this.item.fetch().done(
this.renderItem.bind(this, this.item)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment