Easiest way to reset Backbone's model to initial defaults?

PhD picture PhD · Jul 31, 2011 · Viewed 40.2k times · Source

My models already have a defaults hash. When parts of the view/page are reset, I wish to reset the models back to their original defaults.

Currently, I explicitly set each attribute to its default value. Is there anything built in or a JavaScript/Underscore.js/Backbone.js/jQuery function that I could use to do this in a single statement?

Answer

Peter Lyons picture Peter Lyons · Jul 31, 2011
myModel.clear().set(myModel.defaults);