O'Reilly logo

Mastering Ember.js by Mitchel Kelonye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining class instance methods

Classes can also define instance methods. These methods have a similar signature to object properties, as shown in the following code:

var MyClass = ClassName.extend({
  methodName: function(){
    // method implementation
  }
});

Ember.js provides the ability to reuse implementations of parent methods in extended classes by the use of the _super() method. For example, the following example reimplements and reuses the logX method in the Point class:

var MyPoint = Point.extend({
  logX: function(){
   var x = this._super(); // call parent method
   console.log('x: %s', x);
  }
});
var myPoint = MyPoint.create({
  x: 3
});
myPoint.logX(); // x: 3

Ember.js objects usually define a constructor method called init(), which is called on an instance ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required