leafo/moonscript — Issue #25: static class variable
Author: changtimwu
Created: 2012-01-05 08:24:03+00:00
State: open

I read through the reference manual. It seems that moonscript's doesn't support the semantics of static class variable, which is common in most OOP languages( ex. C++, Java).

I come up with my own implementation as the following. If anyone know a better way do it, please leave comments. Thank you.

``` moon
class Stone
static: { scount: 0 }
new: =>
@static.scount+=1
print 'scount = ', @static.scount

s1= Stone()
s2= Stone()
s3= Stone()
s4= Stone()
s5= Stone()
print 'total stones = ', Stone.static.scount
```