我有一个切片的类型别名,我希望在切片作为指针接收器时能够向切片中添加元素(或从切片中筛选元素):
package main
import (
"fmt"
)
type itself []string
func (h itself) appendToItself(test string) {
h = append(h, test)
}
func main() {
h := itself{"1", "2"}
h.appendToItself("3")
fmt.Println(h, "<- how do I make it [1,2,3]")
}
日志:
[1 2] <- how do I make it [1,2,3]