我是高朗的新手。我正在嘗試使用一個(gè)裝飾器,它返回一個(gè)帶有接收器的函數(shù)。我怎樣才能做到這一點(diǎn)?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 關(guān)注
- 184 瀏覽
添加回答
舉報(bào)
0/150
提交
取消