Skip to content

Commit 61c681d

Browse files
committed
闭包
1 parent 94a7b0d commit 61c681d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ ______
8787

8888
#### 闭包
8989

90-
闭包是指有权访问另一个函数作用域中变量的函数,创建闭包的最常见的方式就是在一个函数内创建另一个函数,通过另一个函数访问这个函数的局部变量,利用闭包可以突破作用链域。
90+
闭包是指有权访问另一个函数作用域中变量的函数,创建闭包的最常见的方式就是在一个函数内创建另一个函数,通过另一个函数访问这个函数的局部变量,利用闭包可以突破作用链域。**闭包表示包括不被计算的变量的函数,也就是说函数可以使用函数之外定义的变量**
9191

9292
特性:
9393
+ 函数内再嵌套函数

闭包.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ fn = function (x){
117117
118118
*/
119119

120+
// 闭包表示包括不被计算的变量的函数,也就是说函数可以使用函数之外定义的变量
121+
var sMessage = 'hello world'
122+
123+
function sayHello(){
124+
console.log(sMessage)
125+
}
126+
sayHello()
127+
128+
var iBassNum = 10
129+
130+
function addNum(sum1,sum2){
131+
function doAdd(){
132+
return sum1 + sum2
133+
}
134+
return doAdd()
135+
}
136+
137+
console.log(addNum(15,68))
138+
139+
140+
141+
120142
function fn(){
121143
var max = 10;
122144
return function bar(x){

0 commit comments

Comments
 (0)