Re:PHP 7's new hashtable implementation
by dsp1234 on Tuesday December 23, 2014 @04:46AM
(#8787486)
Adding non-numeric keys does not remove an Array's "arrayness" in JavaScript
[ Parent
| on HN ]
Re:PHP 7's new hashtable implementation
by nothrabannosir on Tuesday December 23, 2014 @09:14AM
(#8788150)
His point was:
x = [1]; x["test"] = 555; x.map(function (y) { return y; });
// [1]
That's [1], not [1, 555]. You can access the array from the map interface, but not the other way around.The array prototype functions are only specified by the standard to deal solely with numeric keys, but the lines between and object and array are still pretty blurry. The use case for each is different, but the original question far above was "array/map combo. Have you ever seen anything like that in another language?", and clearly JavaScript is very similar even if not exact.
var x = {};
x[0] = 1;
x.length = 1;
x.map = Array.prototype.map;
x.map(function(y) {return y;});
//[1]
Re:PHP 7's new hashtable implementation
by the_mitsuhiko on Tuesday December 23, 2014 @05:40AM
(#8787597)
It does internally. Pretty sure that's even defined in the standard.
Re:PHP 7's new hashtable implementation
by gsnedders on Tuesday December 23, 2014 @07:53PM
(#8791030)
No, it doesn't. The only magic per spec is about the "length" property (which is essentially a getter/setter pair, despite being a data property and not an accessor pair). That's the only thing special about arrays in JS.
Re:PHP 7's new hashtable implementation
by cgrand-net on Tuesday December 23, 2014 @06:25AM
(#8787726)
If you can't observe a difference, does it matter?