method

A function that belongs to an object or type and is called on a value of it, as in name.upper().

In more detail

The value the method is called on is available inside it, as self in Python or this in Java and JavaScript, so the method can read or change it. Methods give a type its own operations; some return a new value, while others change the object in place.

Examples

func (t Target) Address() string {
	return fmt.Sprintf("%s:%d", t.Name, t.Port)
}
Go: func (t Target) Address() string
Java: public String greet() { return "Hello, " + name; }
public String greet() { return "Hello, " + name; }
Node.js APIs are mostly methods on objects such as streams, servers and Buffers.

Related terms

Taught in

References

Certification courses