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:
- Private variables are initialized within class itself and every private variable has public get-method which makes public field read only.
- If you need to set values from outside you should create set-methods and throw an error if value already set.
精彩评论