- Hands-On Full Stack Web Development with Aurelia
- Diego Jose Argüelles Rojas Erikson Haziz Murrugarra Sifuentes
- 119字
- 2021-06-25 20:58:15
Arrow functions
You need to iterate over the elements of an array; normally, you would write something like this:
var data = ['Ronaldo', 'Messi', 'Maradona'];
data.forEach(function (elem) {
console.log(elem)
});
With the arrow functions, you can refactor your code and write something as follows:
var data = ['Ronaldo', 'Messi', 'Maradona'];
data.forEach(elem => {
console.log(elem);
});
The arrow (=>) operator defines a function in one line, making our code readable and ordered. First, you need to declare the inputs; the arrow will send these params to the function body defined by the operator:
// We could transform this
let sum = function(num) {
return num + num;
};
// Into just this
let sum = (num) => num + num;
推薦閱讀
- 智慧城市:大數(shù)據(jù)、互聯(lián)網(wǎng)時代的城市治理(第4版)
- 電子政務效益的經(jīng)濟分析與評價
- HCNA網(wǎng)絡技術
- 計算機網(wǎng)絡與通信(第2版)
- 電力物聯(lián)網(wǎng)工程技術原理與應用
- CCNP TSHOOT(642-832)認證考試指南
- 2小時讀懂物聯(lián)網(wǎng)
- The Kubernetes Workshop
- 面向5G-Advanced的關鍵技術
- 局域網(wǎng)組成實踐
- TCP/IP基礎(第2版)
- 5G非正交多址接入技術:理論、算法與實現(xiàn)
- 現(xiàn)場綜合化網(wǎng)絡運營與維護:運營商數(shù)字化轉型技術與實踐
- 從物聯(lián)到萬聯(lián):Node.js與樹莓派萬維物聯(lián)網(wǎng)構建實戰(zhàn)
- 走近奇妙的物聯(lián)網(wǎng)