Skip to content

Commit 7d324f0

Browse files
deploy: fa27be9
1 parent 482907b commit 7d324f0

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

ch5/ch5-06.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ <h2 id="56-匿名函数"><a class="header" href="#56-匿名函数">5.6. 匿名
168168
<p>更为重要的是,通过这种方式定义的函数可以访问完整的词法环境(lexical environment),这意味着在函数中定义的内部函数可以引用该函数的变量,如下例所示:</p>
169169
<p><u><i>gopl.io/ch5/squares</i></u></p>
170170
<pre><code class="language-Go">// squares返回一个匿名函数。
171-
// 该匿名函数每次被调用时都会返回下一个数的平方的函数
171+
// 该匿名函数每次被调用时都会返回下一个数的平方。
172172
func squares() func() int {
173173
var x int
174174
return func() int {
@@ -178,11 +178,10 @@ <h2 id="56-匿名函数"><a class="header" href="#56-匿名函数">5.6. 匿名
178178
}
179179
func main() {
180180
f := squares()
181-
// () 函数调用符号
182-
fmt.Println(f()()) // &quot;1&quot;
183-
fmt.Println(f()()) // &quot;4&quot;
184-
fmt.Println(f()()) // &quot;9&quot;
185-
fmt.Println(f()()) // &quot;16&quot;
181+
fmt.Println(f()) // &quot;1&quot;
182+
fmt.Println(f()) // &quot;4&quot;
183+
fmt.Println(f()) // &quot;9&quot;
184+
fmt.Println(f()) // &quot;16&quot;
186185
}
187186
</code></pre>
188187
<p>函数squares返回另一个类型为 func() int 的函数。对squares的一次调用会生成一个局部变量x并返回一个匿名函数。每次调用匿名函数时,该函数都会先使x的值加1,再返回x的平方。第二次调用squares时,会生成第二个x变量,并返回一个新的匿名函数。新匿名函数操作的是第二个x变量。</p>

print.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3972,7 +3972,7 @@ <h3 id="542-文件结尾错误eof"><a class="header" href="#542-文件结尾错
39723972
<p>更为重要的是,通过这种方式定义的函数可以访问完整的词法环境(lexical environment),这意味着在函数中定义的内部函数可以引用该函数的变量,如下例所示:</p>
39733973
<p><u><i>gopl.io/ch5/squares</i></u></p>
39743974
<pre><code class="language-Go">// squares返回一个匿名函数。
3975-
// 该匿名函数每次被调用时都会返回下一个数的平方的函数
3975+
// 该匿名函数每次被调用时都会返回下一个数的平方。
39763976
func squares() func() int {
39773977
var x int
39783978
return func() int {
@@ -3982,11 +3982,10 @@ <h3 id="542-文件结尾错误eof"><a class="header" href="#542-文件结尾错
39823982
}
39833983
func main() {
39843984
f := squares()
3985-
// () 函数调用符号
3986-
fmt.Println(f()()) // &quot;1&quot;
3987-
fmt.Println(f()()) // &quot;4&quot;
3988-
fmt.Println(f()()) // &quot;9&quot;
3989-
fmt.Println(f()()) // &quot;16&quot;
3985+
fmt.Println(f()) // &quot;1&quot;
3986+
fmt.Println(f()) // &quot;4&quot;
3987+
fmt.Println(f()) // &quot;9&quot;
3988+
fmt.Println(f()) // &quot;16&quot;
39903989
}
39913990
</code></pre>
39923991
<p>函数squares返回另一个类型为 func() int 的函数。对squares的一次调用会生成一个局部变量x并返回一个匿名函数。每次调用匿名函数时,该函数都会先使x的值加1,再返回x的平方。第二次调用squares时,会生成第二个x变量,并返回一个新的匿名函数。新匿名函数操作的是第二个x变量。</p>

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

searchindex.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)