-
-
Save c0debreaker/d0c2064e5e1eef65fece to your computer and use it in GitHub Desktop.
backbonejs fetch prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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