Skip to content

Instantly share code, notes, and snippets.

@sirjerky
Forked from hankyates/decorator.js
Created April 19, 2014 00:46
Show Gist options
  • Save sirjerky/11069887 to your computer and use it in GitHub Desktop.
Save sirjerky/11069887 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 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