Search code examples
javascriptbackbone.jsbackbone-model

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


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?


Solution

  • myModel.clear().set(myModel.defaults);