learn go function callback

package main

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

import (
    "fmt"
)

func main () {
    callback(1, Add)
}

func Add(a, b int) {
    fmt.Printf("The sum of %d and %d is: %d\n", a, b, a+b);
}

func callback(y int, f func(int, int)) {
    f(y, 2) // this becomes Add(1, 2)
}

 

posted on 2015-11-22 18:04  zengjf  阅读(195)  评论(0编辑  收藏  举报

导航