While looking through apps written with Ember.js, I noticed that sometimes arrays are defined with a call to Ember.A()
and sometimes array literals are used. When I ran Ember.A([1])
in the browser console, the return value looks just like an array and arrays created using array literals had the Ember.js methods pushObject
and friends. Is the call to Ember.A()
just a way to define an Ember.Array
when you don't use prototype extensions? Otherwise are arrays all created equal?
Asked
Active
Viewed 2.0k times
35

hekevintran
- 22,822
- 32
- 111
- 180
1 Answers
47
Your question contains the correct answer: Ember.A()
just a way to define an Ember.Array
when you have turned off the prototype extensions. You'll notice that Ember's internal code always uses Ember.A()
.

jorgehmv
- 3,633
- 3
- 25
- 39

Luke Melia
- 8,389
- 33
- 41
-
3The prototype extensions can be disabled by setting `ENV.EXTEND_PROTOTYPES = false` before loading Ember. They're enable by default. – Jo Liss Jul 01 '12 at 10:06
-
1how do you create and Ember.A() of length 6? – SuperUberDuper Feb 02 '15 at 15:56
-
3probably better as a new question, but it's: `Ember.A(new Array(6))` – Luke Melia Feb 03 '15 at 20:21
-
2Also note that within an Ember app, just defining `myArray = []` ember will beef it up to become an Ember.A() be default unless you do `window.EXTEND_PROTOTYPES = false;` as @JoLiss has mentioned. http://emberjs.com/guides/configuring-ember/disabling-prototype-extensions/ – Eric D. Johnson Mar 19 '15 at 20:41