Skip to content

Instantly share code, notes, and snippets.

@misantronic
Last active December 3, 2015 17:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misantronic/160c0d1828a051df8be4 to your computer and use it in GitHub Desktop.
Save misantronic/160c0d1828a051df8be4 to your computer and use it in GitHub Desktop.
Make Backbone.Model's fetch() return the model ifself
Backbone.Model.extend({
/**
* Return the model itself instead of fetched-data object
* @param {Object} [options]
* @returns {jQuery}
*/
fetch: function (options) {
options = options || {};
var self = this;
var defer = $.Deferred();
Backbone.Model.prototype.fetch.call(this, _.extend(options, {
success: function (/* data */) {
defer.resolve(self);
},
error: function() {
defer.reject.apply(this, arguments);
}
}));
return defer.promise();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment