// --- Getter
def f(var x) { // The value of x is the original value of a, in this case nil
return 100; // The return value is the new value of a
}
@getter(f)
var a; // same as: @f var a
a = 1;
print(a); // No matter what the value of a is, it will always output 100
// --- Setter
def g(var y){ // The value of y is assigned to the value of b, this time is 1
return 200; // The return value is the new value of b
}
@setter(g)
var b;
b = 1;
print(b); // output 100
def g(var x) {
return self.y; // self is Foo instance auto binding by accessor
}
class Foo() {
def __init__() {
self.y = 200;
}
@g
var x;
}
var foo = Foo();
print(foo.x);