Skip to content

Instantly share code, notes, and snippets.

@PaulMougel
Created April 1, 2015 08:13
Show Gist options
  • Save PaulMougel/7442c6946c4bd428c7a9 to your computer and use it in GitHub Desktop.
Save PaulMougel/7442c6946c4bd428c7a9 to your computer and use it in GitHub Desktop.
javascript bind
$ node test2.js
1
2
3
NaN
4
var Counter = function () {
this.count = 0;
this.tick = function () {
this.count++;
console.log(this.count);
}
};
var myCounter = new Counter();
myCounter.tick();
myCounter.tick();
myCounter.tick();
setTimeout(myCounter.tick, 1000)
setTimeout(myCounter.tick.bind(myCounter), 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment