Skip to content

Commit

Permalink
unset accepts var args
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed Nov 11, 2011
1 parent 0c08ab8 commit d87144d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,20 @@
// Remove an attribute from the model, firing `"change"` unless you choose
// to silence it. `unset` is a noop if the attribute doesn't exist.
unset : function(attrs, options) {
var key = attrs;
if (_.isString(key)) (attrs = {})[key] = void 0;
if (_.isString(attrs)) {
var key, args = _.toArray(arguments), attrs = {};
while (_.isString(key = args.shift())) attrs[key] = void 0;
options = key;
}
(options || (options = {})).unset = true;
return this.set(attrs, options);
},

// Clear all attributes on the model, firing `"change"` unless you choose
// to silence it.
clear : function(options) {
var attrs = {};
for (var attr in this.attributes) if (attr != this.idAttribute) attrs[attr] = void 0;
return this.unset(attrs);
var keys = _.without(_.keys(this.attributes), 'id');
return this.unset.apply(this, keys.concat([options]));
},

// Fetch the model from the server. If the server's representation of the
Expand Down

0 comments on commit d87144d

Please sign in to comment.