I’m seeing this weird behavior on Ember objects where when I alter an array that I instance.get, the changes will apply to the class default value (and consequently, to any new instance of the object).
However, if I set the alter as a computed property, it works well (since it ensures that I always send a new instance of the array).
I am wondering is this is normal behavior, it doesn’t seem to me like it should, but it’s very possible that I misunderstand a few things.
Here’s an example (available live in this jsfiddle):
A = Ember.Object.extend
array: []
a = A.create()
a.get('array').pushObject('something') # same with push
b = A.create()
b.get('array') # ['something']
B = Ember.Object.extend
array: ( ->
[]
).property()
a = B.create()
a.get('array').pushObject('something else')
b = B.create()
b.get('array') # []
Here is a good explanation: http://codebrief.com/2012/03/eight-ember-dot-js-gotchas-with-workarounds/ chapter 6. tl;dr: When you want to have an array as an attribute, initialize it in the constructor, something like
updated fiddle: http://jsfiddle.net/Sly7/atjVu/4/