learn go anonymous function

package main

// 参考文档:
//     https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/06.8.md

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 on 2015-11-22 18:14  zengjf  阅读(152)  评论(0编辑  收藏  举报

导航