package main

import (
	"fmt"
)

//定义一个类型
type tsh struct {
	//定义成员,类型是func() string
	test func() string
}

//定义一个函数,获取tsh类型
func New(fn func() string) *tsh {
	return &tsh{
		test: fn,
	}
}
func cre() string {
	return fmt.Sprintf("%s,来了", "tsh")
}

func main() {
	//new完得到tsh类型,调用该结构体的test成员,该成员是个函数
	res := New(cre).test()
	fmt.Println(res)
}

某些类的逻辑非常复杂,简化代码帮助理解下逻辑  

相关文章:

  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2021-10-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
  • 2021-06-09
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案