Properties in classes

We have talked a lot about the Dynamic type, but now, we are going to talk about something else: properties.

Use

Sometimes, you would like to be able to react to the access to an object's property. Whether this is when reading from or assigning to the property, the only way to do that is through the use of functions.

It would then be possible to use it with some code looking like this:

myObject.getValue();
//or
myObject.setValue("This is my new value");

This is a non-natural way of accessing properties, and it can make the code really difficult to read, particularly if you are going to chain calls.

With properties, we will be able to define our functions setValue and getValue so that we can react to accesses to our properties. ...

Get haXe 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.