JS笔记:ES6 Arrow functions

An arrow function does not create its own this, the this value of the enclosing execution context is used.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

function Person(){
  this.age = 0;

  setInterval(() => {
    this.age++; // |this| properly refers to the person object
  }, 1000);
}

var p = new Person();

https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/

你可能感兴趣的:(JS笔记:ES6 Arrow functions)