Iva*_*van 7 syntax function go
以下函数声明中的(c App)是什么?
func (c App) SaveSettings(setting string) revel.Result {
--------------------------------------------------------------------------------------
func Keyword to define a function
(c App) ????
SaveSettings Function name
(setting string) Function arguments
revel.Result Return type
Run Code Online (Sandbox Code Playgroud)
two*_*two 14
(c App)
给出接收器的名称和类型,Go相当于C++或JavaScript this
或Python self
.c
这里是接收者的名字,因为在Go中传统上使用一个简短的,上下文相关的名称,而不是像通用的那样this
.见http://golang.org/ref/spec#Method_declarations -
方法是具有接收器的功能.接收器通过方法名称之前的额外参数部分指定.
和它的例子:
func (p *Point) Length() float64 {
return math.Sqrt(p.x * p.x + p.y * p.y)
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2679 次 |
最近记录: |