-
-
Save Phrogz/1a74e3fcfe0a37432a46aed96a7f45b3 to your computer and use it in GitHub Desktop.
A useful JS function for running maps on objects; similar to Ruby's Symbol#to_proc &:foo syntax, but more powerful.
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
function ƒ(name){ | |
let v,params=Array.prototype.slice.call(arguments,1); | |
return o=>(typeof (v=o[name])==='function' ? v.apply(o,params) : v); | |
} | |
a = ["foo", "barmitzvah"] | |
a.map(ƒ('length')) // [3, 10] | |
a.map(ƒ('toUpperCase')) // ["FOO", "BARMITZVAH"] | |
a.map(ƒ('slice',1)) // ["oo", "armitzvah"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment