What is go's this
(or self
in python) construct?
type Shape struct {
isAlive bool
}
func (shape *Shape) setAlive(isAlive bool) {
}
in the setAlive
function how do I do this.isAlive = isAlive;
?
What is go's this
(or self
in python) construct?
type Shape struct {
isAlive bool
}
func (shape *Shape) setAlive(isAlive bool) {
}
in the setAlive
function how do I do this.isAlive = isAlive;
?
In your example, shape
is the receiver. You could even write it like this:
func (this *Shape) setAlive(isAlive bool) {
this.isAlive = isAlive
}