Reputation: 13
I’m a little confused about something in Ember with the object model, specifically relating to controllers. I have a base class with a property that is an array and I’m extending two controllers from the base class. The array on the base class seems to persist across both instances of the base class; although, I thought Ember would make them two separate instances of the class. Crude example: http://emberjs.jsbin.com/firovahoxera/1/
Shouldn’t the base class instantiate as two different instances or am I thinking about this wrong? Thanks in advance.
Upvotes: 1
Views: 79
Reputation: 47367
Array's are objects in the sense that adding it to the controller adds a reference to that array to all instances of the controller.
If you want an instance on all of your controllers you can create the array on init.
App.BaseClassController = Ember.Controller.extend({
setupPersists: function(){
this.set('persists', []);
}.on('init')
});
http://jsbin.com/firovahoxera/2/edit
Upvotes: 1