|
Spec-Zone .ru
спецификации, руководства, описания, API
|
The following access modifiers apply to script and instance members: instance functions, script functions, instance variables, and script variables. With the exception of protected access, they also apply to classes.
Table 8.1. Primary Access Modifiers
These primary access modifiers apply to all forms of access: creation and reference to classes, calling functions, reading and writing of script or instance variables, and overriding and setting or binding in an object literal of an instance variable.
Because of the central use of object literals in JavaFX, instance variables tend to be externally visiable -- and therefore need more refined access modifiers. Two access modifiers apply only to instance and script var.
Table 8.2. var Access Modifiers
| public-read | The var can be read anywhere. |
| public-init | The var can be initialized or read anywhere. Where initialized means set (but not bound) in an object literal. |
Note that public-read is permitted with def, but that it is equivalent to public.
These access modifiers are additive with the primary access modifiers. Here are some examples:
Table 8.3. Access Modifier Examples
| var x; | Declare a variable. The variable can be initialized (in an object literal), can be overridden (in a subclass), can be read, assigned, or bound (in the default expression or in an object literal initialization). The default access permission is script only access, so, without access modifiers, a variable can be initialized, overridden, read, assigned, or bound from within the script only. |
| def x = 100; | Define x. What you see is what you get. Definitions cannot be changed. They cannot be initialized (in an object literal), cannot be overridden (in a subclass), and cannot be assigned to. The value of the definition can be read. Since the default access permission is script only access, without access modifiers, a definition can be read from within the script only. The definition can be to a bound expression. |
| public var x; | Declare a public variable. This variable can be initialized, overridden, read, assigned, or bound from anywhere. |
| public def x = "Hi"; | A public definition of x. This definition can be read anywhere. A definition cannot be assigned, initialized (in an object literal) or overridden no matter what the access permissions. |
| protected var x; | Declare a variable accessible from the package or subclasses. (see protected, above, for the twisty parts) |
| protected def x = bind z; | Define x which is readable from the package or subclasses. |
| package var x; | Declare a variable accessible from the package. |
| package def x = 42; | Define x to be package readable. |
| public-read var x; | A variable which can be read anywhere, but can only be initialized or written (assigned or bound) within the script (since script access is the default). |
| public-read package var x; | A variable which can be read anywhere, but can only be initialized or written (assigned or bound) within the package. |
| public-init var x; | A variable which can be initialized (by an object literal) or read anywhere, but can only be written (assigned or bound) within the script (since script only access is the default). |
| public-init package var x; | A variable which can be initialized (by an object literal) or read anywhere, but can only be written (assigned or bound) within the package. |