箭头函数
JavaScript 充满了我们需要编写在其他地方执行的小函数的情况。
arr.forEach(func)——forEach对每个数组元素都执行func。setTimeout(func)——func由内建调度器执行。
箭头函数没有this,如果访问 this,则会从外部获取。
javascript
let user = {
name: 'dano',
eat: ["apple", "peal"],
showEat() {
this.eat.forEach((value,index,array) => {
console.log(this.name + " eat "+value);
})
}
}
user.showEat();箭头函数的这种特性可以将其==视为外层函数的一部分==,箭头函数“的”this,就是外层函数的this。