Skip to content

Instantly share code, notes, and snippets.

@Daniel-Hug
Last active January 4, 2016 02:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daniel-Hug/8554212 to your computer and use it in GitHub Desktop.
Save Daniel-Hug/8554212 to your computer and use it in GitHub Desktop.
Sudo methods in JS
var sudo = (function(arr, obj) {
[
['forEach', arr, 'each'],
['map', arr],
['indexOf', arr],
['filter', arr],
['hasOwnProperty', obj, 'has'],
['toString', obj]
].forEach(function(method) {
var fn = method[1][method[0]];
obj[method[2] || method[0]] = fn.call.bind(fn);
});
return obj;
})([], {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment