Re: inheritance
Re: inheritance
- Subject: Re: inheritance
- From: Axel Luttgens <email@hidden>
- Date: Thu, 15 Jan 2004 13:51:31 +0100
julifos wrote:
Shouldn't a loaded script object inherit everything from the main script into
which it was loaded.
No. It is a new instance of a script object with its own methods,
properties, etc.
[...]
You must explicitly call "my parent". Eg:
#################### loaded script
to doIt()
set my parent's z to 4
end doIt
####################
Yes, you are right, as z would otherwise be treated as a variable local
to handler doIt().
Now, as William initially asked about inheritance, "my" instead of "my
parent's" could be more relevant.
If you allow, I'll thus add following to your message.
If the loaded script doesn't override the definition of z, "my z" would
refer to the inherited property z.
On the other hand, if the loaded script defines a property z (thus
overriding z's definition), "my z" would refer to that property, leaving
the parent's one unaffected.
So, let's define the loader as:
property x : "Hey!"
set test to load script alias "
Data:Users:luttgens:Desktop:test.scpt"
tell test to doThat()
and first consider this loaded script:
on doThat()
display dialog (my x as string)
display dialog (my parent's x as string)
end doThat
Running the loader yields two consecutive dialogs, both displaying
"Hey!". [1]
Now, let's slightly modify the loaded script:
property x : "Hello!"
on doThat()
display dialog (my x as string)
display dialog (my parent's x as string)
end doThat
Running the loader now opens a first dialog with "Hello!",and a second
one with "Hey!". [2]
[1] Again one of those cases where an intermediate evaluation seems
mandatory (ie. "as string")...
[2] Here, the first "as string" may be omitted.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.