doc: create arrow function section

This commit is contained in:
Leon Xu committed 2021-09-08 21:13:05 -07:00
1 parent f7ccfab7db
commit 52f628fc81
1 file changed
+28 -1
+28 -1
View File
@@ -28,4 +28,31 @@ show();
setTimeout(function () {
console.log('Execute later after 1 second')
}, 1000);
```
```
## 箭头函数
创建匿名函数的简写
以下的函数:
```javascript
let show = function () {
console.log('Anonymous function');
};
```
可以缩写为:
```javascript
let show = () => console.log('Anonymous function');
```
当然,函数里面的参数也可以应用:
```javascript
let add = function (a, b) {
return a + b;
};
```
=
```javascript
let add = (a, b) => a + b;
```
更多的内容,可以参考[这里](https://www.javascripttutorial.net/javascript-anonymous-functions/)