docs: 匿名函数

This commit is contained in:
Shikong 2021-09-21 02:09:22 +08:00
parent 90c1c5c344
commit 710789c47c

View File

@ -0,0 +1,17 @@
package main
import "fmt"
func main() {
// 匿名函数
// 在函数内部 无法声明 带名称的函数
f1 := func(x, y int) {
fmt.Println("exec anonymous fun: ", x+y)
}
f1(1, 2)
// 如果只调用一次的函数 可以 简写为 立即执行函数
func(x, y int) {
fmt.Println("exec once anonymous fun: ", x+y)
}(5, 5)
}