033闭包函数AGAIN
package main
import "fmt"
func main() {
tf1 := GetTaskFunc("武松")
tf2 := GetTaskFunc("李逵")
p1 := tf1(13)
p2 := tf2(31)
p1 = tf1(12)
p2 = tf2(2)
fmt.Println("武松的进度=",p1)
fmt.Println("李逵的进度=",p2)
}
/*获得任务函数,其状态被包裹在闭包中*/
func GetTaskFunc(name string) func(hours int)(progress int){
var progress = 0
ExeuteTask := func(hours int)int {
fmt.Printf("%s带队行军%d小时\n",name,hours)
progress += hours
return progress
}
return ExeuteTask
}
本文标题:033闭包函数AGAIN
本文链接:https://www.haomeiwen.com/subject/fugpqltx.html
网友评论