Class Ember.computed
publicThis helper returns a new property descriptor that wraps the passed
computed property function. You can use this helper to define properties
with mixins or via Ember.defineProperty()
.
The function you pass will be used to both get and set property values. The function should accept two parameters, key and value. If value is not undefined you should set the value first. In either case return the current value of the property.
A computed property defined in this way might look like this:
var Person = Ember.Object.extend({
firstName: 'Betty',
lastName: 'Jones',
fullName: Ember.computed('firstName', 'lastName', function(key, value) {
return this.get('firstName') + ' ' + this.get('lastName');
})
});
var client = Person.create();
client.get('fullName'); // 'Betty Jones'
client.set('lastName', 'Fuller');
client.get('fullName'); // 'Betty Fuller'
Note: This is the preferred way to define computed properties when writing third-party libraries that depend on or use Ember, since there is no guarantee that the user will have prototype extensions enabled.
You might use this method if you disabled Prototype Extensions. The alternative syntax might look like this (if prototype extensions are enabled, which is the default behavior):
fullName: function () {
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')