In Ember.js, we can call the extend() method on Ember.Object to define a new ember class.
Example :
App.Person = Ember.Object.extend({
say: function(thing) {
alert(thing);
}
});
The above example defines a new App.Person class with a say() method.
We can also create a subclass from any existing class by calling its extend() method. See the following example if you want to create a subclass of Ember's built-in Ember.View class.
Example :
App.PersonView = Ember.View.extend({
tagName: 'li',
classNameBindings: ['isAdministrator']
});
While defining a subclass, you can override methods but still access the implementation of your parent class by calling the special _super() method.
Example :
App.Person = Ember.Object.extend({
say: function(thing) {
var name = this.get('name');
alert(name + " says: " + thing);
}
});
AppApp.Soldier = App.Person.extend({
say: function(thing) {
this._super(thing + ", sir!");
}
});
var sam = App.Soldier.create({
name: "Free Time Leaarn"
});
sam.say("Reporting"); // alerts "Free Time Leaarn says: Reporting, sir!"