Set a property on a model or object. For the reverse, checkout ianstormtaylor/get
.
$ component install ianstormtaylor/set
Plain objects:
var set = require('set');
var person = { name: 'ulysses' };
set(person, 'name', 'achilles');
person.name; // achilles
Getter/setter methods:
var set = require('set')
, model = require('model');
var Person = model('person').attr('name');
var person = new Person({ name: 'ulysses' });
set(person, 'name' 'achilles');
person.name(); // achilles
Get methods:
var Backbone = require('backbone')
, set = require('set');
var person = new Backbone.Model({ name: 'ulysses' });
set(person, 'name', 'achilles'));
person.get('name'); // achilles
Get the model
's prop
to
value`.
MIT