Skip to content

Instantly share code, notes, and snippets.

@daronwolff
Created May 20, 2016 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daronwolff/ba7413095fe671842ac473713ac9b5d2 to your computer and use it in GitHub Desktop.
Save daronwolff/ba7413095fe671842ac473713ac9b5d2 to your computer and use it in GitHub Desktop.
Write a methodize, a function that converts a binary function to a method
function add(a,b) {
return (a + b);
}
function methodize(func) {
return function(y){
return func(this,y);
}
}
Number.prototype.add = methodize(add);
(2).add(3) // 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment