-
-
Save PaulMougel/7442c6946c4bd428c7a9 to your computer and use it in GitHub Desktop.
javascript bind
This file contains 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
$ node test2.js | |
1 | |
2 | |
3 | |
NaN | |
4 |
This file contains 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
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