From 331cb8bedea21e61128056608714d7dbd117db86 Mon Sep 17 00:00:00 2001
From: Jeremy Ashkenas
- defaultsmodel.defaults
+ defaultsmodel.defaults or model.defaults()
- The defaults hash can be used to specify the default attributes
- for your model. When creating an instance of the model, any unspecified
- attributes will be set to their default value.
+ The defaults hash (or function) can be used to specify the default
+ attributes for your model. When creating an instance of the model,
+ any unspecified attributes will be set to their default value.
diff --git a/test/model.js b/test/model.js
index b90f77d5..5a313dc9 100644
--- a/test/model.js
+++ b/test/model.js
@@ -172,6 +172,17 @@ $(document).ready(function() {
var model = new Defaulted({two: null});
equals(model.get('one'), 1);
equals(model.get('two'), null);
+ Defaulted = Backbone.Model.extend({
+ defaults: function() {
+ return {
+ "one": 3,
+ "two": 4
+ };
+ }
+ });
+ var model = new Defaulted({two: null});
+ equals(model.get('one'), 3);
+ equals(model.get('two'), null);
});
test("Model: change, hasChanged, changedAttributes, previous, previousAttributes", function() {