go 闭包函数

一、什么是闭包函数?

 

二、匿名函数可以被赋值给变量并作为值使用:

package main

import "fmt"

func main(){
	f()
}

func f(){
	for i := 0; i<4; i++{
		g := func(i int){fmt.Printf("%d", i)}
		g(i)
		fmt.Printf("-g is of type %T and has value %v\n",g,g)
	}
}

  

posted @ 2018-07-25 17:45  liubiaos  阅读(179)  评论(0编辑  收藏  举报