Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // store the `this` scope in
- // a variable to reuse
- function Person () {
- var that = this;
- that.age = 0;
- setInterval(function growUp () {
- that.age += 1;
- }, 1000)
- }
- // bind the function's `this`
- function Person () {
- this.age = 0;
- setInterval(function growUp () {
- this.age += 1;
- }.bind(this), 1000)
- }
Add Comment
Please, Sign In to add comment