Skip to content

Instantly share code, notes, and snippets.

@hankyates
Last active August 29, 2015 13:57
Show Gist options
  • Save hankyates/9680619 to your computer and use it in GitHub Desktop.
Save hankyates/9680619 to your computer and use it in GitHub Desktop.
// 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
@hankyates
Copy link
Author

Whoops. yeah yall are right. does the updated gist make it a little more clear?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment