【ES6】箭头函数

let getPrices = () => 4.55
console.log(getPrices())

let arr = ['apple', 'banana', 'orange']
arr.forEach(value => {
    console.log(value)
})
arr.forEach((value, index) => {
    console.log(value, index)
})

function Person() {
  var self = this;
  self.age = 0;

  setInterval(function growUp() {
    self.age++;
  }, 1000);
}

function Person(){
  this.age = 0;

  setInterval(() => {
    // this 指向 person 对象
    this.age++;
  }, 1000);
}

var person = new Person();
原文地址:https://www.cnblogs.com/jzm17173/p/5852768.html