Here's what the documentation has to say about physical properties (also known as backing fields):
A field is considered to be physical if it is either
- variable
- a property with the read-access or write-access identifier being
default
or null
- a property with
:isVar
metadata
So you can set up a property that fully consists of calculated values. Think a read-only property giving you the area of a rectangle as a function of width and height, or think of a property that is backed by some other property and just returns/sets width and height in a different unit. Or maybe you just want to name your backing fields differently, say m_width
and m_height
.
The :isVar
is helpful in situations where the property access rules etc. laid out above would let the compiler think that there is no backing field needed. In that case, the code would fail (from the docs again):
// This field cannot be accessed because it
// is not a real variable
public var x(get, set):Int;
function get_x() {
return x;
}
function set_x(x) {
return this.x = x;
}
By adding :isVar
you basically tell the compiler that you absolutely want the backing field. The other option for your particular case would be to use default,default
, in which case the compiler knows there is an automatic backing field required and access should be restricted according to the access level of the property (public
or private
):
public var propertyInt(default, default):Int;
In that case you might also use a variable directly, because the net effect is in essence the same:
public var propertyInt : Int;