Language Guide

CHAPTER 9
Script Objects
Inheritance and Delegation 275
Even though script X in Figure 9-3 sends itself the getName command, the
command is intercepted by the child script, which substitutes its own version
of the getName handler. AppleScript always maintains the first target of a
command as the “self” to which inherited commands are sent, redirecting to
the child any inherited commands the parent sends to itself.
The relationship between a parent script object and its child script objects is
dynamic. If the properties of the parent change, so do the inherited properties
of the children. For example, the script object Simple in the following script
inherits its Vegetable property from script object John.
script John
property Vegetable : "Spinach"
end script
script Simple
property parent : John
end script
set Vegetable of John to "Swiss chard"
Vegetable of Simple
--result: "Swiss chard"
When you change the Vegetable property of script object John with the Set
command, you also change the Vegetable property of the child script object
Simple. The result of the last line of the script is "Swiss chard".
Similarly, if a child changes one of its inherited properties, the value of the
parent property changes. For example, the script object JohnSon in the
following script inherits the Vegetable property from script object John.
script John
property Vegetable : "Spinach"
end script
script JohnSon
property parent : John
on changeVegetable()
set my Vegetable to "Zucchini"
end changeVegetable
end script