# 🏅 5/13 (四) 每日任務 Day 14
###### tags: `Vue 直播班 - 2021 夏季班`
參考文章: https://wcc723.github.io/javascript/2017/12/21/javascript-es6-arrow-function/
教學
---
箭頭函式的運用技巧如下:
```js=
// 傳統函式
function saySomething(string) {
return '接招' + string;
}
// 轉成箭頭函式
const saySomething = (string) => {
return '接招 ' + string;
}
```
```js=
// 當只有單行表達式時,可同時省略 return 及 {}
// 省略後依然保有回傳的特質
const saySomething = (string) => '接招 ' + string;
console.log(saySomething('菜鳥!'));
// 不過要注意,如果有使用 {},就需要自行加上 return
const saySomething = (string) => {'接招 ' + string};
console.log(saySomething('菜鳥!')); // 會回傳 undefined
```
```js=
// 只有一個參數可以不加括號 ()
const saySomething = string => '接招 ' + string;
console.log(saySomething('菜鳥!'));
// 沒有參數、參數有兩個以上都不能省略 ()
const saySomething = () => '接招 菜鳥!';
console.log(saySomething());
```
題目 (請貼上 CodePen)
---
請將以下程式碼簡化為箭頭函式 (不影響結果的情況下進行最大簡化)
```js=
// 題目一
function sum(a, b) {
let c = a + b;
return c;
}
console.log(sum(5, 6));
// 題目二
function square(num) {
return num * num;
}
console.log(square(5))
// 題目三
setTimeout(function() {
console.log('延遲 1 秒');
}, 1000);
// 題目四
let arr = [1, 2, 3];
let arrNew = arr.map(function(item, i) {
return item * i;
});
console.log(arrNew);
// 題目五
let obj = {
fn: function fn2(a) {
return a * a;
}
}
console.log(obj.fn(10));
```
回報流程
---
請同學依照下圖教學觀看解答、回報答案:

回報格式如下圖,請在「回報區」使用註解回報答案 (為了統計人數,請同學依序加上「報數」)

<!-- 解答
// 題目一
const sum = (a, b) => {
let c = a + b;
return c;
}
console.log(sum(5, 6));
// 題目二
let square = num => num * num;
console.log(square(5));
// 題目三
setTimeout(() => console.log('延遲 1 秒'), 1000);
// 題目四
let arr = [1, 2, 3];
let arrNew = arr.map((item, i) => item * i);
console.log(arrNew);
// 題目五
let obj = {
fn: a => a * a
}
console.log(obj.fn(10));
-->
回報區
---
<!-- 01: Jasmin
codepen:https://codepen.io/thejasmin/pen/PoWjejL
-->
<!-- 2: Harold
codepen: https://codepen.io/YuWin0805/pen/bGqEjyG
-->
<!-- 3: Eric-小偉哥
codepen: https://codepen.io/ericLoveDesign/pen/RwprBmE?editors=1111
-->
<!-- 4: Sec
codepen: https://codepen.io/Sentiments/pen/QWpyBey?editors=1111
-->
<!-- 5: Alpha
codepen: https://codepen.io/alphatero/pen/KKWVxPM
-->
<!-- 6: Ethan
codepen: https://codepen.io/blazer030/pen/oNZbPgP
-->
<!-- 7: youting
codepen: https://codepen.io/youtingluo/pen/QWpyVjN?editors=0011
-->
<!-- 8.小魚
codepen: https://codepen.io/jarvis1993/pen/xxqZaZj?editors=0010
-->
<!-- 9.Li Shang
codepen: https://codepen.io/li-shang/pen/mdWVGyg
-->
<!-- 10.Lina Chen
codepen: https://codepen.io/LinaChen/pen/jOBWvqM
-->
<!-- 11: Vic
codepen: https://codepen.io/hsuan333/pen/MWpKqWp
-->
<!--12:yijun
codepen:https://codepen.io/sandy3068/pen/XWMXPaE
-->
<!--13:leolee
codepen:https://codepen.io/nekorice/pen/abJdjJp
-->
<!-- 14: Echo Hui
codepen: https://codepen.io/echohuiecho/pen/NWpxLMd?editors=0011 -->
<!-- 15: 圈圈
codepen: https://codepen.io/wei-the-lessful/pen/ZEeQMvv -->
<!--16: Yi Chieh
codepen: https://codepen.io/Yi-Chieh/pen/mdWVGYV
-->
<!--17: Yiren
codepen: https://codepen.io/Yiren_Liou/pen/JjWGaez?editors=1012
-->
<!--18: Joe Kuo
codepen: https://codepen.io/alertislow/pen/GRWoYRq?editors=0011
-->
<!--19: Chiang
codepen: https://codepen.io/ChiangJ/pen/dyvGgXo?editors=0011
-->
<!--20: Izumi 泉
codepen: https://codepen.io/izumi-dev/pen/gOgEZzM
-->
<!--20: shoppingq
codepen: https://codepen.io/shoppingq/pen/abJdQzZ
-->
<!-- 22: Jay
codepen: https://codepen.io/jayredk/pen/yLMeRmd?editors=1111
-->
<!-- 23: Poseidon
codepen: https://codepen.io/posidomcode/pen/KKWVwQX
-->
<!-- 24: Alvin Chu
codepen:https://codepen.io/wave99487chu/pen/WNprYxm
-->
<!-- 25: Larry
codepen:
https://codepen.io/manpower0708/pen/GRWowWB?editors=1010
-->
<!-- 26: Iva
codepen:
https://codepen.io/Hsu1Fang/pen/abJdPOq?editors=1011
-->
<!-- 27: peter.chen1024
https://codepen.io/JIAN-RONG/pen/WNprLEG?editors=0012
-->
<!-- 28: Ted Kuo
https://codepen.io/TedKuo/pen/RwprvdZ
-->
<!-- 29:Dah
https://codepen.io/hua0124/pen/jOBWJob
-->
<!-- 30: wel
https://codepen.io/uwhhiaxx/pen/ZEeQPrW?editors=0012
-->
<!-- 31: Amanda Chiang
https://codepen.io/cym199922/pen/zYZrXEj?editors=0011
-->
<!-- 32: Fred Chang
https://codepen.io/fred8196/pen/QWpyPRM
-->
<!-- 33: tim Chou
https://codepen.io/tim-chou/pen/rNyxgEN?editors=1111
-->
<!-- 34: Echo
https://codepen.io/eni13718/pen/XWMXvJa?editors=1112
-->
<!-- 35:陳sam
https://codepen.io/euldpliv/pen/YzZwmLo?editors=1111
-->
<!-- 36: Wendy Li
https://codepen.io/rockayumitw/pen/bGqEXrp?editors=0011
-->
<!-- 37: Erica
https://codepen.io/ericadu/pen/dyvGxKL
-->
<!-- 報數 38: RitaHuang
https://codepen.io/Rita-Rossweisse/pen/KKWVOBq?editors=0012
-->
<!-- 報數 39: Alysa Chan
https://codepen.io/alysachan/pen/RwprXRO?editors=0011
-->
<!-- 40: jimmyFang
https://codepen.io/pohxiqqo/pen/WNpwNeY?editors=0012
-->
<!-- 41: carrie
https://codepen.io/echocarriet/pen/MWpyWqK
-->
<!-- 42: 涂阿銘
https://codepen.io/asd40441/pen/vYxGELb?editors=0011
-->
<!-- 43: 阿倫
https://codepen.io/jason5125122/pen/XWMXQzE
-->
<!-- 44: Ed Huang
https://codepen.io/yide1986/pen/WNpwrXG?editors=0012
-->
<!-- 45: Stacey Huang
https://codepen.io/staceyhuang/pen/BaWKjMz?editors=1011
-->
<!-- 46:Alicia Lo
https://codepen.io/dkcyhyre/pen/mdWPEjG
-->
<!-- 47:Iven
https://codepen.io/rtorihnk/pen/jOBqmWa?editors=1011
-->
<!--48: Valerie
https://codepen.io/vicky-chang/pen/bGqpRmy?editors=1012
-->
<!--49: YOYO
https://codepen.io/lumedkle/pen/OJpNxJR?editors=1011
-->
<!--50: Jack
https://codepen.io/pen/?editors=0011
-->
<!--51:allen chou
https://codepen.io/eepson123tw/pen/qBrZGdv?editors=1111
-->
<!--52:林晉
https://codepen.io/linchinhsuan/pen/NWpNZNL?editors=0012
-->
<!-- 53:Tofu Tseng
https://codepen.io/Tofutseng/pen/dyvXPOK?editors=0011
-->
<!-- 54:Jordan Tseng
https://codepen.io/jordan-ttc-design/pen/mdWEymv?editors=1012
-->
<!-- 55: Jessie Cheng
https://codepen.io/JessieMosbi/pen/gOmMpEW?editors=0011
-->
<!-- 56: Oober
https://codepen.io/xtsjrjdv/pen/bGqeVyJ?editors=0010
-->
<!-- 57: twoz
https://codepen.io/twoz/pen/dyvXZdW?editors=0012
-->
<!-- 58: Carol
https://codepen.io/taonong/pen/GRWpEve
-->
<!-- 59: Ming
https://codepen.io/BigMine/pen/MWpeMjL?editors=0011
-->
<!-- 60: moitw
https://codepen.io/tsuifei/pen/ZEepQjL?editors=0011
-->
<!-- 61: Eyan
https://codepen.io/somebody1997/pen/VwpKyYM?editors=1011
-->
<!-- 62: Emily Hsi
https://codepen.io/EmilyHsi/pen/YzZpmPN
-->
<!-- 63: 李重炫
https://codepen.io/otherway1123/pen/ZEeBgPQ?editors=0112
-->
<!-- 64: Amber
https://codepen.io/amberTing/pen/YzZZOBV?editors=0011
-->
<!-- 65: MM
https://codepen.io/MINN3/pen/dyvWXBx
-->