Skip to content

Instantly share code, notes, and snippets.

@amoilanen
Last active August 29, 2015 14:05
Show Gist options
  • Save amoilanen/f9a6bc30963ebe022ffd to your computer and use it in GitHub Desktop.
Save amoilanen/f9a6bc30963ebe022ffd to your computer and use it in GitHub Desktop.
Mapping function as method
if (!Function.prototype.asMethod) {
Function.prototype.asMethod = function() {
var self = this;
return function(first) {
var rest = [].slice.call(arguments, 1);
return self.apply(first, rest);
}
};
}
var arr = ["Abc", "ABc", "ABC"];
var lowerCase = arr.map(String.prototype.toLowerCase.asMethod());
console.log(lowerCase);
//["abc", "abc", "abc"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment