Skip to content

Instantly share code, notes, and snippets.

@sudodoki
Created August 19, 2013 20:44
Show Gist options
  • Select an option

  • Save sudodoki/6273936 to your computer and use it in GitHub Desktop.

Select an option

Save sudodoki/6273936 to your computer and use it in GitHub Desktop.
// Get the model's index by id or fall back to underscore's method
indexOf: function(sought) {
if (typeof sought === "string") {
if (!this._byId[sought]) {
return -1;
};
if (_.indexOf.call(_, this.pluck('id'), sought) !== -1) {
return _.indexOf.call(_, this.pluck('id'), sought)
}
return _.pluck(this.models, 'cid').indexOf(sought)
} else {
return _.indexOf.call(_, this.models, sought);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment