我是高朗的新手。我正在尝试使用一个装饰器,它返回一个带有接收器的函数。我怎样才能做到这一点?type myStruct struct { s string}func myFunc(s string) { fmt.Println(s)}// Here I want to return a function with a receiverfunc (*myStruct) myDecorator(fn func(string)) (*myStruct)func(string){ return (ms *myStruct)func(s string) { fn(ms+s) }}func main() { ms := myStruct{"Hello"} // Some func is function with receiver as myStruct pointer someFunc := myDecorator(myFunc) // This is expected to print "Hello world" ms.someFunc(" world")}
目前暂无任何回答
- 0 回答
- 0 关注
- 140 浏览
添加回答
举报
0/150
提交
取消