Created
May 24, 2013 12:41
-
-
Save tobie/5643236 to your computer and use it in GitHub Desktop.
Looking for a good name for that sort of pattern, and more specifically how to name the `sortBy` function to best convey what it does.
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 sortBy(prop) { | |
return function(a, b) { | |
return a[prop].localeCompare(b[prop]); | |
} | |
} | |
[ | |
{ foo: "some text", bar: "other text" }, | |
{ foo: "hello", bar: "world" }, | |
{ foo: "More text", bar: "MOAR" } | |
].sort(sortBy('foo')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's just a higher-order function. Being a closure would imply some context to be captured, but here you're passing it to the function so it's not happening.
About naming the function, I believe that
sortBy
conveys the right information and would not change it.