Created
May 20, 2016 22:03
-
-
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
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
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