Re: Script Objects - help please!!
Re: Script Objects - help please!!
- Subject: Re: Script Objects - help please!!
- From: has <email@hidden>
- Date: Sun, 12 Jun 2005 22:12:44 +0100
Simon Forster wrote:
>>Dynamic scope is determined at runtime when 'my <variable>' (or '<variable> of me') invokes dymanic lookup of a variable, but follows different rules so I won't bother going into that unless you need it.
>
>Question: To make sure that the handler references its "closest" variable (in this instance I'm talking about properties declared in the script object), I've used the "x of me" grammar - which _seems_ to be working fine. According to your rules, this isn't necessary - and you hint at unexpected consequences.
Dynamic lookup starts at the currently targetted script object and searches along its inheritance chain until it finds the desired variable (or runs out of places to look). Example:
script Foo
property x : 1
property y : 2
on getX()
return x -- permanently bound to Foo's property x at compile-time
end getX
on getY()
return my y -- looked up at runtime, starting with original recipient of getY message
end getY
end script
script Bar
property parent : Foo
property x : 10
property y : 20
end script
tell Bar to {getX(), getY()} --> {1, 20}
(Overriding properties is bad design, mind; the above example is merely to demonstrate the differences in how lexical vs dynamic binding works.)
>Is this likely to come back and bite me? Should I just go through my library script and delete all these unnecessary "of me"s? (A bit of a shot in the dark for you without seeing the entire context but I'd like to hear your opinion).
I doubt it will make a difference in your case. Though as a general principle of good design, one should avoid unnecessary code.
If you're curious to see practical examples of library and OO design, check out AppleMods' libraries <http://applemods.sourceforge.net/>; some interesting stuff there. e.g. The Types library has some good basic OO code in it.
HTH
has
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden