From 52f628fc814879bb9ba33d1dafb64a68697e3851 Mon Sep 17 00:00:00 2001 From: Leon Xu <6479451-leonxu260@users.noreply.gitlab.com> Date: Wed, 8 Sep 2021 21:13:05 -0700 Subject: [PATCH] doc: create arrow function section --- source/_posts/匿名函数.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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