码迷,mamicode.com
首页 > 其他好文 > 详细

ES6箭头函数

时间:2019-03-19 18:27:01      阅读:163      评论:0      收藏:0      [点我收藏+]

标签: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)        

  你们学会了吗?

ES6箭头函数

标签:ons   箭头函数   javascrip   function   语句   cti   log   OLE   括号   

原文地址:https://www.cnblogs.com/yibadejiu/p/10560304.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!