Go 方法首先是 class 函数吗?
Are Go methods first class functions?
标题基本上说明了一切..
我可以在运行时创建一个 returns 另一个 Go 方法的 Go 方法吗?一个简单的例子:
type Person struct {
name string
age uint
}
func (p Person) createGetNameMethod() /*return signature is a method for Person*/ {
return /*return a new anonymous method here for Person*/
}
Are Go methods first class functions?
是的,他们是。
Can I create a Golang method that returns another Golang method [...]?
当然可以。
[Can I] return a new anonymous method [?]
不,当然不是。
方法集是在编译时确定的。方法 是 正常的,第一个 class 函数,但它们不能在运行时更改或创建:
您可以return方法集中存在的方法,但不能将方法添加到方法集中。
反射允许这样的事情,但在你的情况下不行。
标题基本上说明了一切..
我可以在运行时创建一个 returns 另一个 Go 方法的 Go 方法吗?一个简单的例子:
type Person struct {
name string
age uint
}
func (p Person) createGetNameMethod() /*return signature is a method for Person*/ {
return /*return a new anonymous method here for Person*/
}
Are Go methods first class functions?
是的,他们是。
Can I create a Golang method that returns another Golang method [...]?
当然可以。
[Can I] return a new anonymous method [?]
不,当然不是。
方法集是在编译时确定的。方法 是 正常的,第一个 class 函数,但它们不能在运行时更改或创建:
您可以return方法集中存在的方法,但不能将方法添加到方法集中。
反射允许这样的事情,但在你的情况下不行。