开发者

How can i make an object unmodifiable in flex

I am having a configuration object in my flex3.5 application. I want that object to be unmodif开发者_JS百科iable so that no one can change any property in it once it is created.


If you're talking about a generic Object, it's impossible since it's dynamic. What you want to do is create a class that has only 'getter' functions and every property is specified in the constructor.

If you want to have it still bindable, look at my blog post about bindable read-only properties.


Use get/set methods. There is can be two strategies:

  1. Private variables are initialized within class itself and every private variable has public get-method which makes public field read only.
  2. If you need to set values from outside you should create set-methods and throw an error if value already set.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜