-
-
Save sirjerky/11069887 to your computer and use it in GitHub Desktop.
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
// 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 addCallCount = countDecorator(Add); | |
Add(1, 1); | |
// -> 2 Dont pay attention to this number. The important part is we called the `Add` function once. | |
addCallCount(); | |
// -> 1 | |
Add(2, 2); | |
// -> 4 Dont pay attention to this number either. The important part is we called the `Add` function again. | |
addCallCount(); | |
// -> 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment