I have a dynamic Actionscript class as follows:
public dynamic class Foo {....}
In my code I (may) add some properties to it:
myFoo["myNewDynamicProp"] = "bar";
Elsewhere in my code, given an instance of class Foo, how can I determine if that dynamic property has been added already without throwing an expensive exception?
You can do one of three things. First, calling a property that doesn’t exist on a dyanmic instance doesn’t throw an exception. It just returns
undefined, so you can just test for that. Or you can use theinkeyword. Or you can use thehasOwnProperty()method.Consider the following:
You could also just as easily use bracket notation for the first example:
myFoo['nothing']