Timeline for Are Javascript arrays primitives? Strings? Objects?
Current License: CC BY-SA 2.5
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 19, 2011 at 3:28 | comment | added | Jared Farrish | @connrs - I swear I used to get an error when using foo.var without first declaring foo['var']. I SWEAR. | |
| Feb 19, 2011 at 2:51 | history | edited | connrs | CC BY-SA 2.5 |
added 432 characters in body
|
| Feb 19, 2011 at 2:46 | comment | added | connrs | Ah. I suppose pointing out that it would produce unexpected results is a better angle to take. Editing it now | |
| Feb 19, 2011 at 2:43 | comment | added | Šime Vidas |
@connrs In your answer you say that this is invalid: foo['bar'] = 'totallyinvalid'; But that is not true. It is valid. That's my point.
|
|
| Feb 19, 2011 at 2:41 | comment | added | connrs | @slifty: Indeed. Array literals are objects as I mentioned above. arrays inheriting from the Array prototype methods such as length push and pop which are absent for pure Object literals | |
| Feb 19, 2011 at 2:39 | comment | added | connrs |
@Šime Vidas: Indeed but var foo=[0,1]; foo.bar=2; for(var i=0;i<foo.length;i++){console.log(foo[i]);} will not work as expected with novice javascript developers
|
|
| Feb 19, 2011 at 2:35 | comment | added | slifty | Careful connrs. Arrays have those methods because they ARE objects, whose prototype has been given those functions. | |
| Feb 19, 2011 at 2:28 | comment | added | Šime Vidas |
@connrs Not true. Arrays can have properties just like any other objects: var arr = []; arr.foo = 'Totally fine!';
|
|
| Feb 19, 2011 at 2:25 | history | edited | connrs | CC BY-SA 2.5 |
added 265 characters in body
|
| Feb 19, 2011 at 2:19 | history | answered | connrs | CC BY-SA 2.5 |