Changeset 2335 for cobra/trunk/HowTo/111-UseProperties.cobra
- Timestamp:
- 03/20/10 04:42:28 (2 years ago)
- Files:
-
- 1 modified
-
cobra/trunk/HowTo/111-UseProperties.cobra (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/HowTo/111-UseProperties.cobra
r2127 r2335 44 44 45 45 # Many properties just cover for an underlying variable. When that 46 # is the case, you can use a shortcut syntax es. Later, you can46 # is the case, you can use a shortcut syntax. Later, you can 47 47 # change the property to the full form in order to add logic. 48 48 … … 61 61 62 62 63 # You can even pack an initial value into the declaration 64 # which also be used to infer the data type. 65 66 class Person3 67 68 pro name from var = '' # inferred as String 69 70 pro age from var = 0 # inferred as int 71 72 63 73 # In this shortcut syntax, the vars were already declared so 64 74 # the property simply "... from var": 65 75 66 class Person 376 class Person4 67 77 68 78 var _name as String … … 88 98 # you can specify that name instead of "var": 89 99 90 class Person 4100 class Person5 91 101 92 102 var _name as String … … 101 111 # Properties can be read-only: 102 112 103 class Person 5113 class Person6 104 114 105 115 cue init(name as String)



