Allow Model#get to accept multiple arguments #2232

wants to merge 2 commits into


None yet
2 participants

akre54 commented Feb 2, 2013

Finally growing frustrated with seeing code blocks like this

var a = book.get('a');
var b = book.get('b');
var c = book.get('c');


in my code, I decided to write up a quick pull to allow this beautifulness instead:

_.each(book.get('a', 'b', 'c'), doSomething);

or just

var letters = book.get('a', 'b', 'c');
console.log(letters); // ['foo', 'bar', 'baz']

This will give Model#get closer feature parity with Model#set, which can take multiple attribute/value pairs as arguments to assign.


tgriesser commented Feb 2, 2013

I think this would be better addressed with pick, if some of the proposed underscore methods in your request on #2082 are merged.


akre54 commented Feb 2, 2013

Agreed, but I thought the semantics of model.pick / model.pluck were a
little too oddly named. This pull actually suffers from another problem in
that has and others rely on get, and may not be easy to workaround. I'll
fix this tomorrow or close the pull.


akre54 commented Feb 2, 2013

I don't really have a solution to the get/has semantics. I'd still prefer get to be overloaded instead of using _.values(model.pick('name', 'title')), but as get handles a lot in Backbone internals, I guess I'll have to deal with a little more typing for now.

@akre54 akre54 closed this Feb 2, 2013

@akre54 akre54 deleted the akre54:model-get-multiple-attrs branch Feb 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment