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
", g, g)
    }
}
原文地址:https://www.cnblogs.com/zengjfgit/p/4986363.html