documentcloud/backbone — pull request #680 by braddunbar (2011-10-20 03:16:58+00:00)
Title: Model.set takes a single key/value pair

I often find that I need to set one key/value pair on a model and that the key is stored in a variable. This usually requires something like the following:

var attrs = {};
attrs[key] = val;
model.set(attrs);

Sometimes, if `attrs` is already defined, this can be shortened to:

(attrs = {})[key] = val;
model.set(attrs);

This, however, is about as small as it gets. Also it's less clear than my proposed solution:

model.set(key, val);

This cuts down on boilerplate and allows for interesting bindings. I know other solutions have been posted (#570 for instance) but I think this approach is simpler and more readable.