Skip to content

Instantly share code, notes, and snippets.

@prestonp
Last active August 29, 2015 14:07
Show Gist options
  • Save prestonp/fecf05c06e15853692bc to your computer and use it in GitHub Desktop.
Save prestonp/fecf05c06e15853692bc to your computer and use it in GitHub Desktop.
demethodizing
// 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