Guest User

Untitled

a guest
Mar 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. // store the `this` scope in
  2. // a variable to reuse
  3. function Person () {
  4. var that = this;
  5. that.age = 0;
  6. setInterval(function growUp () {
  7. that.age += 1;
  8. }, 1000)
  9. }
  10.  
  11. // bind the function's `this`
  12. function Person () {
  13. this.age = 0;
  14. setInterval(function growUp () {
  15. this.age += 1;
  16. }.bind(this), 1000)
  17. }
Add Comment
Please, Sign In to add comment