model.js
function(def, withArray) {
    def = def ? def : _.result(this, 'definition');

    return _.reduce(def, function(defaults, attr, key) {
      if (attr.computed) {
        return defaults;
      }
      if (attr.default !== undefined) {
        defaults[key] = _.result(attr, 'default');
      } else if (attr.type === 'object') {
        defaults[key] = this.defaults(attr.fields || {});
      } else if (attr.type === 'array') {
        // withArray to populate nested array values for _validateAttributes
        defaults[key] = withArray ? [this.defaults(attr.fields || {})] : [];
      } else {
        defaults[key] = this._defaultVal(attr.type);
      }
      return defaults;
    }.bind(this), {});
  }
function(def, withArray) {
    def = def ? def : _.result(this, 'definition');

    return _.reduce(def, function(defaults, attr, key) {
      if (attr.computed) {
        return defaults;
      }
      if (attr.default !== undefined) {
        defaults[key] = _.result(attr, 'default');
      } else if (attr.type === 'object') {
        defaults[key] = this.defaults(attr.fields || {});
      } else if (attr.type === 'array') {
        // withArray to populate nested array values for _validateAttributes
        defaults[key] = withArray ? [this.defaults(attr.fields || {})] : [];
      } else {
        defaults[key] = this._defaultVal(attr.type);
      }
      return defaults;
    }.bind(this), {});
  }
function ( def , withArray ) { def = def ? def : _ . result ( this , 'definition' ) ; return _ . reduce ( def , function ( defaults , attr , key ) { if ( attr . computed ) { return defaults ; } if ( attr . default !== undefined ) { defaults [ key ] = _ . result ( attr , 'default' ) ; } else if ( attr . type === 'object' ) { defaults [ key ] = this . defaults ( attr . fields || { } ) ; } else if ( attr . type === 'array' ) { // withArray to populate nested array values for _validateAttributes defaults [ key ] = withArray ? [ this . defaults ( attr . fields || { } ) ] : [ ] ; } else { defaults [ key ] = this . _defaultVal ( attr . type ) ; } return defaults ; } . bind ( this ) , { } ) ; }
Get the default attribute values for your model.
When creating an instance of the model,
any unspecified attributes will be set to their default value.

Define defaults as a function.

@param  {Object} def
@param  {boolean} withArray
@return {Object}
Get the default attribute values for your model . When creating an instance of the model any unspecified attributes will be set to their default value .