码迷,mamicode.com
首页 > 其他好文 > 详细

learn go function callback

时间:2015-11-22 18:53:05      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

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)
}

 

learn go function callback

标签:

原文地址:http://www.cnblogs.com/zengjfgit/p/4986342.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!