|
|
箭头函数的进本组成包括:函数参数,箭头,函数体。
1.语法
①.一个参数
- let count = pic => pic;
- //相当于:
- function count(pic){
- retun pic;
- }
复制代码
②.多个参数
- let count = (pic,num) => `${pic},{num}`;
- //相当于
- function count(pic,num){
- retun pic + "," + num;
- }
复制代码 ③.空参数,需要一个空小括号()
④.函数体多个语句,需要用函数体包含起来
- let count = (pic,num)=>{
- let total = pic*num;
- return total;
- }
- console.log(count(2,5))//10
复制代码
⑤.箭头返回是一个对象
- let count = (pic,num) =>({
- pic:pic,
- num:num
- })
- console.log(count(2,5))//{pic:2,num:5}
复制代码
|
|