In Python, you can something like this:
>>> list(map(str.upper, ['foo','bar']))
['FOO', 'BAR']
I would like to be able to do something similar in javascript:
I’ve tried the following in Chrome using the native map implementation ( https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map ):
['foo','bar'].map(String.prototype.toUpperCase)
['foo','bar'].map(String.prototype.toUpperCase.call)
Why doesn’t call work?
Is there any elegant way to do this or must I wrap toUpperCase in a callback function?
Thx
Modern browsers support this (although it is a recent addition)
or even
example: http://www.jsfiddle.net/xPsba/