samples/JavaScript/json2_backbone.js
function(model, options) {
      options || (options = {});
      model = this._prepareModel(model, options);
      if (!model) return false;
      var already = this.getByCid(model) || this.get(model);
      if (already) throw new Error(["Can't add the same model to a set twice", already.id]);
      this._byId[model.id] = model;
      this._byCid[model.cid] = model;
      var index = options.at != null ? options.at :
                  this.comparator ? this.sortedIndex(model, this.comparator) :
                  this.length;
      this.models.splice(index, 0, model);
      model.bind('all', this._onModelEvent);
      this.length++;
      if (!options.silent) model.trigger('add', model, this, options);
      return model;
    }
function(model, options) {
      options || (options = {});
      model = this._prepareModel(model, options);
      if (!model) return false;
      var already = this.getByCid(model) || this.get(model);
      if (already) throw new Error(["Can't add the same model to a set twice", already.id]);
      this._byId[model.id] = model;
      this._byCid[model.cid] = model;
      var index = options.at != null ? options.at :
                  this.comparator ? this.sortedIndex(model, this.comparator) :
                  this.length;
      this.models.splice(index, 0, model);
      model.bind('all', this._onModelEvent);
      this.length++;
      if (!options.silent) model.trigger('add', model, this, options);
      return model;
    }
function ( model , options ) { options || ( options = { } ) ; model = this . _prepareModel ( model , options ) ; if ( ! model ) return false ; var already = this . getByCid ( model ) || this . get ( model ) ; if ( already ) throw new Error ( [ "Can't add the same model to a set twice" , already . id ] ) ; this . _byId [ model . id ] = model ; this . _byCid [ model . cid ] = model ; var index = options . at != null ? options . at : this . comparator ? this . sortedIndex ( model , this . comparator ) : this . length ; this . models . splice ( index , 0 , model ) ; model . bind ( 'all' , this . _onModelEvent ) ; this . length ++ ; if ( ! options . silent ) model . trigger ( 'add' , model , this , options ) ; return model ; }
Internal implementation of adding a single model to the set, updating hash indexes for `id` and `cid` lookups. Returns the model, or 'false' if validation on a new model fails.
Internal implementation of adding a single model to the set updating hash indexes for id and cid lookups . Returns the model or false if validation on a new model fails .