学习目标:
*如何正确的使用箭头函数
*箭头函数中this指向哪个对象
一.HTML中函数的定义方法
let aaa = function(){}
let bbb = {function(){}}
let ccc = () => {}
二.箭头函数参数与代码
let sun = (num1,num2) =>{
return num1+num2
}
当箭头函数只有一个参数时参数小括号可省
const power = num1 =>{
return num1*num1
}
当箭头函数只有一行代码时代码中括号可省
const sun = (num1,num2) => num1+num2
三.箭头函数的this指向
let hhh={
a(){
setTimeout(function(){
console.log(this);
})
//打印window
setTimeout(() => {
console.log(this);
})
//打印object
//箭头函数中的this是向外查找this的定义 this -- a
}
}