标签:ons 箭头函数 javascrip function 语句 cti log OLE 括号
E6S越来越火,不会箭头函数就out了,今天就来讲一下箭头函数得使用!!
//普通写法
function func (text) {
console.log(text);
}
func(‘普通函数‘);
//箭头函数写法
let func2 = (text)=>{
console.log(text);
}
func2(‘箭头函数‘);
//一个参数箭头函数省略括号写法
let func3 = text=>{
console.log(text);
}
func3(‘一个参数箭头函数省略括号写法‘);
//return语句只有一句得时候return和大括号{}都能去掉
let arr = [1,2,3,4,5];
let func4 = arr.map(function(item,index){
return item > 2?‘普通函数‘:‘箭头函数‘
})
let func4 = arr.map(item =>{
return item > 2?‘普通函数‘:‘箭头函数‘
});
let func4 = arr.map(item => item > 2?‘普通函数‘:‘箭头函数‘)
console.log(func4)
你们学会了吗?
标签:ons 箭头函数 javascrip function 语句 cti log OLE 括号
原文地址:https://www.cnblogs.com/yibadejiu/p/10560304.html