Spec-Zone .ru
спецификации, руководства, описания, API

Chapter 8. Access Modifiers

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

  Script only access: This is the default when no primary access modifier is supplied. Script only access means that it can only be accessed within the script where it is defined
package Package access: Can only be accessed within the package where it is defined.
protected Protected access: Can be accessed from the package where it is defined and from subclasses of the class where it is defined. That is probably all you really need to know about protected access -- but if you want the details, read on.... A protected member of an object may be accessed from outside the package in which it is declared only by code that is responsible for the implementation of that object. Which means: Let C be the class in which a protected member m is declared. Access is permitted only within the body of a subclass S of C. In addition, if Id denotes an instance variable or instance function, then: If the access is by a qualified name Q.Id, where Q is an ExpressionName, then the access is permitted if and only if the type of the expression Q is S or a subclass of S. If the access is by a variable access expression E.Id, where E is a Primary expression, or by a function invocation expression E.Id(. . .), where E is a Primary expression, then the access is permitted if and only if the type of E is S or a subclass of S.
public Public access: can be accessed anywhere.

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.