我是高朗的新手。我正在嘗試使用一個裝飾器,它返回一個帶有接收器的函數。我怎樣才能做到這一點?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 關注
- 174 瀏覽
添加回答
舉報
0/150
提交
取消