Language Guide
CHAPTER 9
Script Objects
Using the Copy and Set Commands With Script Objects 285
copy JohnSon to J1
copy JohnSon to J2
tell J1 to changeVegetable("Zucchini")
tell J2 to changeVegetable("Swiss chard")
Vegetable of J1
--result: "Zucchini"
Vegetable of J2
--result: "Swiss chard"
Vegetable of John
--result: "Spinach"
You can create handlers that construct copies of script objects for use elsewhere
in a script. For example, the script that follows includes a handler that takes an
initial balance as a parameter and creates a copy of a script object that acts as
an independent account. Each copy includes several properties and an on
deposit handler that enables the script object to increment its own balance
when it receives a Deposit command.
on makeAccount(initialBalance)
script account
property StartDate : current date
property Balance : initialBalance
on deposit(amount)
set Balance to Balance + amount
end deposit
end script
end makeaccount
set a to makeAccount(3300)
set b to makeAccount(33)