7. EMBER.JS
• Ember is a JavaScript framework for creating
ambitious web applications that eliminates
boilerplate and provides a standard application
architecture.
• Formerly known as AmberJS – formerly known as
SprouteCore 2
• Emberjs.com
• Ember.js VS. Backbone.js
9. THE EMBER OBJECT MODEL
Person = Ember.Object.extend({
say: function(thing) {
alert(thing);
}
});
var person = Person.create();
person.say("Hello") // alerts "Hello"
10. THE EMBER OBJECT MODEL
// Passing in an object
var tom = Person.create({
name: "Tom Dale",
helloWorld: function() {
this.say("Hi my name is " + this.get('name'));
}
});
tom.helloWorld() // alerts "Hi my name is Tom Dale"
11. THE EMBER OBJECT MODEL
// Reopening Classes and Instances
Person.reopen({
isPerson: true
});
Person.create().get('isPerson') // true
Person.reopen({
// override `say` to add an ! at the end
say: function(thing) {
this._super(thing + "!");
}
});
12. COMPUTED PROPERTIES
Person = Ember.Object.extend({
// these will be supplied by `create`
firstName: null,
lastName: null,
fullName: function() {
var firstName = this.get('firstName');
var lastName = this.get('lastName');
return firstName + ' ' + lastName;
}.property('firstName', 'lastName')
});
var tom = Person.create({
firstName: "Tom",
lastName: "Dale"
});
tom.get('fullName') // "Tom Dale"