Prev | Current Page 231 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

This
is needed to permit syntax like the following:
var v = c.step++;
Where step is a property defined this way:
public var step(getStep,setStep) : Int;
private function getStep() : Int
{
return counter;
}
private function setStep(value : Int) : Int
{
counter += 1;
return counter;
}
If setStep doesn ??™ t return a value, v will be set to Void on the contrary of what one would
logically expect.
112
Part I: The Core Language
The modifiers permit to limit the access to a variable from outside the class and this can be handy in the
blog entry example to force the createdOn variable to be read - only so that its value is set at its creation
and can ??™ t be forged later.
public var createdOn(default,null) : Date;
Trying to access the createdOn property will work fine if the value is read but reports an error if a value
is assigned.
class Main
{
static function main()
{
var entry : BlogEntry = new BlogEntry(???My First Entry???, ???...???);
trace(entry.createdOn); // works
entry.createdOn = Date.


Pages:
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243