Created
January 14, 2014 05:04
-
-
Save jefflembeck/8413366 to your computer and use it in GitHub Desktop.
I feel like this functionality should and likely already does exist. I just can't seem to get it in my head.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.superMap = function( fn ){ | |
return this.map( function( x ){ | |
return fn.call(x); | |
} | |
}; |
[ "hi", "how", "are", "you" ].map( String.prototype.toUppercase.call );
TypeError: String.prototype.toUppercase is undefined
[allong.es] has send
that can be used to make something like this:
allong = require('allong.es');
var send = allong.es.send;
[ "hi", "how", "are", "you" ].map(send('toUpperCase'));
//=>
[ 'HI',
'HOW',
'ARE',
'YOU' ]
Not exactly the same, but there are some other features you may want to consider if you implement superMap
, such as being able to take some parameters:
var map = allong.es.map;
map([ "hi", "how", "are", "you" ], send('concat', ' (pause)'))
//=>
[ 'hi (pause)',
'how (pause)',
'are (pause)',
'you (pause)' ]
That's fantastic. Thanks @raganwald. Picking up your book on this. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is the DREAM (for some value of dream)