HaxeDoc2

(やまだぃちぅ) #1

We can learn from this that a variable


1.has a name (here:member),

2.has a type (here:String),

3.may have a constant initialization (here:"bar") and

4.may have access modifiers (4.4) (here:static)

The example first prints the initialization value ofmember, then sets it to"foo"before print-
ing its new value. The effect of access modifiers is shared by all three class field kinds and
explained in a separate section.
It should be noted that the explicit type is not required if there is an initialization value. The
compiler will infer (3.6) it in this case.


inline

extern

static None

No ’this’ Anything

No Yes

No
Yes

static

Invalid Constants only

No Yes

Yes No

Figure 4.1: Initialization values of a variable field.

4.2 Property


Next to variables (4.1), properties are the second option for dealing with data on a class. Unlike
variables however, they offer more control of which kind of field access should be allowed and
how it should be generated. Common use cases include:



  • Have a field which can be read from anywhere, but only be written from within the defining
    class.

Free download pdf