mirror of
https://gitee.com/shikong-sk/golang-study
synced 2025-05-22 18:08:10 +08:00
docs: 匿名函数
This commit is contained in:
parent
90c1c5c344
commit
710789c47c
17
base/function/anonymous/main.go
Normal file
17
base/function/anonymous/main.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user