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

Reopening classes and instances

Sometimes, it is necessary to update class implementations without redefining them. This is usually necessary when we do not wish to extend built-in classes, but only want to update their implementations. Ember.js refers to this as reopening of classes and objects. Class methods and properties can be reimplemented using the reopenClass method, while instance methods and properties can be updated using the reopen method. It's however discouraged to change built-ins as they may change in future versions.

For example:

var Book = Em.Object.extend(); Book.reopen({ id: null, title: null, purchase: function(){ console.log('sold'); } }); Book.reopenClass({ getById: function(id){ return Book.create({ id: '456', title: 'Harry ...

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