Last active
August 29, 2015 13:57
-
-
Save hankyates/9680619 to your computer and use it in GitHub Desktop.
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
// Implement a decorator function that takes | |
// a function as an argument and will track | |
// how many times the passed function was called. | |
function Add(x, y) { | |
return x + y; | |
} | |
var Add = countDecorator(Add); | |
Add(1, 1); | |
// -> 2 Dont pay attention to this number. The important part is we called the `Add` function once. | |
Add.callCount(); | |
// -> 1 | |
Add(2, 2); | |
// -> 4 Dont pay attention to this number either. The important part is we called the `Add` function again. | |
Add.callCount(); | |
// -> 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Whoops. yeah yall are right. does the updated gist make it a little more clear?