mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:34:15 +08:00
update book code
This commit is contained in:
18
eBook/examples/chapter_6/function_closure.go
Normal file
18
eBook/examples/chapter_6/function_closure.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var f = Adder()
|
||||
fmt.Print(f(1)," - ")
|
||||
fmt.Print(f(20)," - ")
|
||||
fmt.Print(f(300))
|
||||
}
|
||||
|
||||
func Adder() func(int) int {
|
||||
var x int
|
||||
return func(delta int) int {
|
||||
x += delta
|
||||
return x
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user