mirror of
				https://github.com/gopl-zh/gopl-zh.github.com.git
				synced 2025-11-04 11:42:06 +00:00 
			
		
		
		
	Update ch5-06.md
返回的是一个函数,而不是返回的这个函数被调用后的返回值
This commit is contained in:
		@@ -13,7 +13,7 @@ strings.Map(func(r rune) rune { return r + 1 }, "HAL-9000")
 | 
			
		||||
<u><i>gopl.io/ch5/squares</i></u>
 | 
			
		||||
```Go
 | 
			
		||||
// squares返回一个匿名函数。
 | 
			
		||||
// 该匿名函数每次被调用时都会返回下一个数的平方。
 | 
			
		||||
// 该匿名函数每次被调用时都会返回下一个数的平方的函数
 | 
			
		||||
func squares() func() int {
 | 
			
		||||
	var x int
 | 
			
		||||
	return func() int {
 | 
			
		||||
@@ -23,10 +23,11 @@ func squares() func() int {
 | 
			
		||||
}
 | 
			
		||||
func main() {
 | 
			
		||||
	f := squares()
 | 
			
		||||
	fmt.Println(f()) // "1"
 | 
			
		||||
	fmt.Println(f()) // "4"
 | 
			
		||||
	fmt.Println(f()) // "9"
 | 
			
		||||
	fmt.Println(f()) // "16"
 | 
			
		||||
        // () 函数调用符号
 | 
			
		||||
	fmt.Println(f()()) // "1"
 | 
			
		||||
	fmt.Println(f()()) // "4"
 | 
			
		||||
	fmt.Println(f()()) // "9"
 | 
			
		||||
	fmt.Println(f()()) // "16"
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user