1.6.18 Tracing the Current Object During Method Calls

this Names the Receiving Object

Inside an instance method, `this` refers to the object that received that method call. The receiver may be reached through any reference to that object.

First and active call TakeTurn on the same Player receiver.
Initial relationship
  • New
  • Changed
  • Removed
Two Aliases Can Call One Player

Suppose `first` and `active` both refer to the same Player. These two calls have the same receiver:

first.TakeTurn();
active.TakeTurn();

Inside each call, `this` refers to that one Player. If `TakeTurn` increments `this.NumberOfTurns`, the Player's count increases twice.

The Variable Name Does Not Become this

The code inside `TakeTurn` does not need to know whether the caller used `first` or `active`. It operates on the Player that received the call.

A Second Player Becomes a Different Receiver

After `active` is assigned a reference to a second Player, `active.TakeTurn()` runs with the second Player as `this`. The first Player retains its earlier count.

The third TakeTurn call reaches a different Player after reassignment.
How the relationship changes
  • New
  • Changed
  • Removed
The Current Object Is Specific to Each Call

The receiver determines `this` for that invocation. A later call can use another receiver, even though the same method definition runs.