Why does
[].reverse.call("string");
fails (error in both firefox and ie, returns the original string in chrome) while calling all other arrays methods on a string work ?
>>> [].splice.call("string",3)
["i", "n", "g"]
>>> [].map.call("string",function (a) {return a +a;} )
["ss", "tt", "rr", "ii", "nn", "gg"]
Because
.reverse()modifies an Array, and strings are immutable.You could borrow
Array.prototype.sliceto convert to an Array, then reverse and join it.Just be aware that in older versions of IE, you can’t manipulate a string like an Array.