diff --git a/source/_posts/匿名函数.md b/source/_posts/匿名函数.md index 324574b..e275a52 100644 --- a/source/_posts/匿名函数.md +++ b/source/_posts/匿名函数.md @@ -28,4 +28,31 @@ show(); setTimeout(function () { console.log('Execute later after 1 second') }, 1000); -``` \ No newline at end of file +``` + +## 箭头函数 +创建匿名函数的简写 +以下的函数: +```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/) \ No newline at end of file