FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

作为值的函数 · dahui4dev/JavaScript-Example@0feb372 · GitHub

Commit 0feb372

Browse files
committed
作为值的函数
1 parent fdc7dcb commit 0feb372

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎article/005-reference-date-regexp.md‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,18 @@ var sum2 = function (num1, num2) {
120120

121121
由以上示例可以看出,下面的函数,在执行到函数所在的语句之前,变量 sum2 不会保存对函数的引用,所以会报语法错误;而上面的函数声明因为存在变量提升(function declaration hoisting),所以可以正常运行。
122122

123+
#### 3.3、作为值的函数
123124

125+
因为函数名本身就是变量,所以函数也可以作为值来使用。
124126

127+
1. 函数可当作参数传递给另一个函数;
128+
2. 函数可作为另一个函数的结果返回。
125129

126-
127-
130+
```javascript
131+
function callSomeFunction(someFunc, someArgs) {
132+
return someFunc(someArgs);
133+
}
134+
```
128135

129136

130137
### 4、基本包装类型

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL