赞
踩
省略函数function,然后在()后面加上=>{}
例
const fn = function(){
}
改为
const fn = ()=> {
}
例
const fn = item => {
}
例
const fn = (item1,item2)=>{
}
例
const test = ()=>{
return '111111'
}
改为
const test = () =>‘111111’
例
const test = () => {
return {
name: '坤哥',
age: 2.5
}
}
改为
const test = () => ({
name: '坤哥'
age: 2.5
})
例
const rel = document.querySelector('#rel')
rel.addEventListener('click', item => {
console.log(this)//指向的是window
const test = () => {
alert(11)
console.log(this) //指向的是window
}
console.log(test());
})
const rel = document.querySelector('#rel')
rel.addEventListener('click', function(item) {
console.log(this)//指向的是rel
const test = () => {
alert(11)
console.log(this) //指向的是rel
}
console.log(test());
})
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。