猿问

如何在不执行变量的情况下将函数分配给变量?

当我尝试将映射键分配给函数时,它会执行该函数。在不执行该功能的情况下如何做到这一点?


var myslice []int

myslice = append(myslice, 1)


func RemoveIndex(s []string, index int) []string {

    return append(s[:index], s[index+1:]...)

}


a["removeIndex"] = removeIndex(myslice, 0)


繁花如伊
浏览 114回答 1
1回答

开心每一天1111

只需将功能分配给map[string]func([]string,int)[]string's 键func RemoveIndex(s []string, index int) []string {    return append(s[:index], s[index+1:]...)}a["removeIndex"] = RemoveIndexrifn := a["removeIndex"]rifn(myslice, 0)
随时随地看视频慕课网APP

相关分类

Go
我要回答