computed_properties.gravity 249 B

123456789101112131415161718
  1. #unittest {
  2. name: "Computed properties.";
  3. result: 700;
  4. };
  5. class foo {
  6. private var _a = 12;
  7. var a {
  8. set {_a = value * 100;}
  9. get {return _a/2;}
  10. };
  11. }
  12. func main() {
  13. var f = foo();
  14. f.a = 14; // 14*100 = 1400
  15. return f.a; // 1400/2 = 700
  16. }