Last active
August 29, 2015 14:05
-
-
Save amoilanen/f9a6bc30963ebe022ffd to your computer and use it in GitHub Desktop.
Mapping function as method
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
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