class instance interface abstract-class extends implements private protected public static const constructor super read-only friendly-method event |
Read-onlyThere are many cases that you want an attribute be read but not written outside. To implement, you may add a getter with nearly no logic inside. It will increase the class size and decrease the readability. This feature can be implemented in ZNOW with simply declaring the property as READ. After declaring it, the property cannot be modified outside but can read outside. Of course, the property can be read and written inside a class. var ClassA=Class({
inc:function(){
this.counter++;
},
counter:READ(0) //declare a read-only attribute
});
var classA=new ClassA();
classA.inc();
//Able to read outside
classA.counter; //>1
//Disable to write outside
classA.counter++; //>forbidden
|