Skip to content

Instantly share code, notes, and snippets.

@thelonecabbage
Created March 12, 2012 08:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thelonecabbage/2020727 to your computer and use it in GitHub Desktop.
Save thelonecabbage/2020727 to your computer and use it in GitHub Desktop.
Recursive toJSON for Backbone.js
Data.Model = Backbone.Model.extend({
toJSON: function(){
var clone = _.clone(this.attributes);
_.each(clone, function (attr, idx) {
if(attr.toJSON){
clone[idx] = attr.toJSON();
}
});
return clone;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment