JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-0.9.7.1.min.js"></script>
<script type="text/x-handlebars">
<div>person1.firstName: {{MyApp.person1.firstName}}</div>
<div>person2.firstName: {{MyApp.person2.firstName}}</div>
</script>
JavaScript
MyApp = Ember.Application.create();
Person = Ember.Object.extend({
firstName: null,
lastName: null,
fullName: Ember.computed(function(key, value) {
if (arguments.length === 1) { // getter
var firstName = this.get('firstName');
var lastName = this.get('lastName');
return firstName + ' ' + lastName;
} else { // setter
var name = value.split(" ");
this.set('firstName', name[0]);
this.set('lastName', name[1]);
return value;
}
}).property('firstName', 'lastName')
});
MyApp.person1 = Person.create({fullName: 'Tyrion Lannister'}); // don't do this! It overwrites the setter method
MyApp.person2 = Person.create().setProperties({fullName: 'Robb Stark'}); // this is OK