Skip to content

Instantly share code, notes, and snippets.

@twokul
Created September 5, 2013 18:14
Show Gist options
  • Save twokul/6453933 to your computer and use it in GitHub Desktop.
Save twokul/6453933 to your computer and use it in GitHub Desktop.
cp-set
App.Person = Ember.Object.extend({
firstName: null,
lastName: null,
fullName: function(key, value, oldValue) {
// setter
if (arguments.length > 1) {
var nameParts = fullNameString.split(/\s+/);
this.set('firstName', nameParts[0]);
this.set('lastName', nameParts[1]);
}
// getter
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')
});
var ironMan = Person.create({
firstName: "Tony",
lastName: "Stark"
});
ironMan.get('fullName'); // Tony Stark
ironMan.set('fullName', "William Burnside");
ironMan.get('fullName'); // William Burnside
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment