Re: difference between property and variable
Re: difference between property and variable
- Subject: Re: difference between property and variable
- From: Brennan <email@hidden>
- Date: Tue, 11 Dec 2007 09:50:04 +0100
On 10/12/07 at 23:11, Mark J. Reed <email@hidden> wrote:
> Apart from weird implementation-related performance differences, I
> consider the most important distinguishing feature of properties to be
> that they keep their values between executions (if the script is not
> recompiled in between, anyway).
Yes, mostly (see below) and when... has <email@hidden> wrote:
> > - A property's scope is limited to the script object in which it's
> > defined. e.g. If you define a property in your main script, that
> > property will cease to exist when the script finishes running
...he might have been [mis]understood to mean that the properties lose
their values between executions. I'm sure it's not what he meant, but I
just wanted to nitpick his otherwise thorough answer.
What hasn't been mentioned in much/any detail is the use of properties in
explicit script objects (rather than the implicit 'top level' script
object that every .scpt represents), so here's a snippet which just teases
out the difference between properties declared 'at the top' and those
declared inside explicit script objects:
(* OOP example *)
property brennan : missing value
set brennan to constructPerson("brown")
set heidi to constructPerson("red")
brennan's announcementAboutHairColor()
heidi's announcementAboutHairColor()
on constructPerson(hc)
script person
property hairColor : ""
on announcementAboutHairColor()
display dialog "My hair is " & hairColor
end announcementAboutHairColor
end script
set person's hairColor to hc
return person
end constructPerson
(* script ends*)
In this case 'brennan' (and his hairColor) will be remembered between
executions of the script (until it is recompiled) whereas heidi (and her
hairColor) will be forgotten because she's not declared as a property of
the .scpt EVEN THOUGH hairColor is declared as a property.
Just wanted to clarify that point.
The great universal truth: Scope ultimately renders all truths meaningless
and valueless.
(Don't tell my girlfriend I'm talking about her like that).
Brennan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden