Skip to content

Instantly share code, notes, and snippets.

@simonwoo
Last active May 18, 2016 15:24
Show Gist options
  • Save simonwoo/ac7fba34f70aaa0195952d6a51ca3b4a to your computer and use it in GitHub Desktop.
Save simonwoo/ac7fba34f70aaa0195952d6a51ca3b4a to your computer and use it in GitHub Desktop.
function foo(num) {
    console.log( "foo: " + num );

    // keep track of how many times `foo` is called
    this.count++;
}

foo.count = 0;

var i;

for (i=0; i<10; i++) {
    if (i > 5) {
        foo( i ); //foo.call(foo, i);
    }
}
// foo: 6
// foo: 7
// foo: 8
// foo: 9

// how many times was `foo` called?
console.log( foo.count ); // 0 -- WTF?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment