CoffeeScript makes this work well:
[name, age] = user.get('name', 'age')
It would be trivially easy to allow Pam.Model
's get
to override Backbone's get
to support this
get('name', 'age')
could return ['john', '45']
, allowing the following:
[name, age] = user.get('name', 'age')
get('name', 'age')
could return { name: 'john', age: 45 }
, allowing both of the following:
{name, age} = user.get('name', 'age')
or
attrs = user.get('name', 'age')
printName(attrs.name)
printAge(attrs.age)
This is much more useful outside of the CoffeeScript world
value = @get('value')
amount_unit = @get('amount_unit')
rate = @get('rate')
rate_unit = @get('rate_unit')
total = @get('total')
claim_type = @get('claim_type')
becomes
[value, amount_unit, rate, rate_unit, total, claim_type] =
@get('value', 'amount_unit', 'rate', 'rate_unit', 'total', 'claim_type')
or
{value, amount_unit, rate, rate_unit, total, claim_type} =
@get('value', 'amount_unit', 'rate', 'rate_unit', 'total', 'claim_type')
or
{value, amount_unit, rate,
rate_unit, total, claim_type} =
@get('value', 'amount_unit', 'rate',
'rate_unit', 'total', 'claim_type')
Generally we wouldn't be using huge blocks like the above example; it'd be most useful for destructuing assignment of 2 or 3 arguments: