documentcloud/backbone — pull request #716 by hx (2011-11-03 22:07:34+00:00)
Title: Allow Model.set/save(key, value) with mixed argument format

This is an alternative to #570.

This modification allows you to use `Model.set` or `Model.save` the regular way, with one or more inline key/value pairs, or a mix of both.

This is a reasonably in-demand addition and @jashkenas has indicated it will be done eventually, so I've tried to implement it in a clean, flexible manner so we can finally see it merged in.

This mod will allow any of the following:

model.set('my-key', value);
model.set('my-key', value, 'another-key', anotherValue); // ad infinitum
model.set('my-key', value, {options: silent});
model.set('my-key', value, 'another-key', anotherValue, {anotherKey: anotherValue}, {moreKeys: moreValues}, {options: silent}); // ad infinitum

After inline key/value pairs are processed, the last argument is assumed to be `options`, so the last version (mixing inline with bundled) will only work if options are included. While clumsy, this will also work:

model.set('my-key', value, {anotherKey: anotherValue}, null);

I added a helper function to minimize repetition between `set()` and `save()`. I've tested it thoroughly with lots of combinations and data types. Null and undefined values, blank keys etc all work fine.

To those involved in #570, I mean no disrespect to you or your work! There's nothing wrong with it. Like you guys, I'm keen to see this feature merged into the master, and hopefully this version gets passed QC nice and quick :)