Last active
August 29, 2015 14:07
-
-
Save prestonp/fecf05c06e15853692bc to your computer and use it in GitHub Desktop.
demethodizing
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
// http://tech.pro/blog/2097/clever-way-to-demethodize-native-js-methods | |
var demethodize = Function.prototype.bind.bind(Function.prototype.call); | |
// demethodize lets you generalize functions over nodelists, jquery objects, and strings | |
var map = demethodize([].map); | |
map('Hello world', function(c) { return c.toUpperCase(); }); | |
// What's more interesting is you can do this despite strings not having a .prototype.map | |
[].map.call('Hello world', function(c) { return c.toUppercase(); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment