Section 8.3. Script Properties


8.3. Script Properties

A script property (often just called a property) is a variable defined and initialized at the top level of a script object through a special statement called a property declaration . The syntax is:

 property propertyName : initialValue 

For example:

 script s     property x : 5 end script 

The abbreviation for property is prop.

A property is a variable, so its value can be set and fetched in the normal way. For example:

 script s     property x : 10     display dialog x -- 10     set x to 5     display dialog x -- 5 end script 

A property declaration can appear only at the top level of a script object. But the script as a whole is a script object. Therefore a property declaration can appear at the top level of the script, and the script object that owns it is the script as a whole. This is a legal script:

 property x : 5 display dialog x 

A script property declaration is like set, not like copy. When a script property is initialized to a value where this makes a difference (a list, a record, a date, or a script object) it is set by reference (see "Set by Reference" in Chapter 7). Here's proof:

 property L : {1, 2, 3} script s     property LL : L     set end of LL to 4 end script run s L -- {1, 2, 3, 4} 




AppleScript. The Definitive Guide
AppleScript: The Definitive Guide, 2nd Edition
ISBN: 0596102119
EAN: 2147483647
Year: 2006
Pages: 267
Authors: Matt Neuburg

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net