Last active
January 4, 2016 02:19
-
-
Save Daniel-Hug/8554212 to your computer and use it in GitHub Desktop.
Sudo methods in JS
This file contains hidden or 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
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