
Message Sending
bankBalance and its three methods, Deposit, Withdraw, and Balance:
bankBalance := {
total: 0,
Deposit: func(amount)
begin
self.total := self.total + amount;
end,
Withdraw:func(amount)
begin
self.total := self.total - amount;
end,
Balance: func()
return self.total,
};
To send messages to these various methods requires no more than
bankBalance:Deposit(50); bankBalance:Withdraw(20); bankBalance:Balance(); 30As each of the three methods executes,
self is the bankBalance frame; it is the frame to which each message is sent. Thus, self.total is the total in the bankBalance frame.
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996