can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
29 lines (19 loc) • 835 B
Markdown
Map.prototype.compute compute
can.Map.prototype 4
Make a can.compute from an observable property.
`map.compute(attrName)`
{String} attrName the property to bind to
{can.compute} a [can.compute] bound to _attrName_
`compute` is a convenience method for making computes from properties
of Observes. More information about computes can be found under [can.compute].
var map = new can.Map({a: 'Alexis'});
var name = map.compute('a');
name.bind('change', function(ev, nevVal, oldVal) {
console.log('a changed from ' + oldVal + 'to' + newName + '.');
});
name(); // 'Alexis'
map.attr('a', 'Adam'); // 'a changed from Alexis to Adam.'
name(); // 'Adam'
name('Alice'); // 'a changed from Adam to Alice.'
name(); // 'Alice'
can.