Are Javascript arrays primitives? Strings? Objects? -
are arrays merely objects in disguise? why/why not? in way(s) (such/not)?
i have thought of arrays , objects in js same, because accessing them identical.
var obj = {'i': 'me'}; var arr = new array(); arr['you'] = 'them'; console.log(obj.i); console.log(arr.you); console.log(obj['i']); console.log(arr['you']);
am mislead/mistaken/wrong? need know js literals, primitives, , strings/objects/arrays/etc...?
are arrays/objects merely strings in disguise? why/why not? in way(s) (such/not)?
arrays objects.
however, unlike regular objects, arrays have special features.
arrays have additional object in prototype chain - namely
array.prototype
. object contains so-called array methods can called on array instances. (list of methods here: http://es5.github.com/#x15.4.4)arrays have
length
property (which live, ergo, auto-updates) (read here: http://es5.github.com/#x15.4.5.2)arrays have special algorithm regarding defining new properties (read here: http://es5.github.com/#x15.4.5.1). if set new property array , property's name sting can coerced integer number (like
'1'
,'2'
,'3'
, etc.) special algorithm applies (it defined on p. 123 in spec)
other these 3 things, arrays regular objects.
read arrays in spec: http://es5.github.com/#x15.4
Comments
Post a Comment