Not in a forward-compatible cross-platform way.

In Javascript, for a general Object, you can say:

  obj = { a: 3 };

  if ('b' in obj) ... obj.b

But OL classes are implemented as actual classes in some target runtimes, and 
in those runtimes, class instances are not plain objects, and the `in` operator 
is not (always) applicable.

Luckily for you, Javascript does have the special "undefined" value [which we 
write as `(void)0`, because some Javascripts do _not_ ensure that `undefined` 
is undefined], which is different from all other values, including `null`.  
Usually this is sufficient to tell whether an attribute has been initialized or 
not.

I'm hedging my bets above because currently, when we compile to swf10 (the 
strictest runtime so far), we do so in a way that the `in` operator _will_ work 
for most, but not all, OL instances; but I wouldn't want you to rely on that, 
because one of the performance features we are considering turning on will make 
that no longer true.

In general, you don't want to be dynamically adding attributes to OL instances, 
so you shouldn't need to test for their existence.  For us to continue to 
support that model going forward, we will pay a performance penalty.

Maybe if you say what you are really trying to do, we can offer a better 
solution?

On 2010-10-29, at 20:22, Antun Karlovac wrote:

> Hi all,
> 
> Does the OL runtime have a way to check if an attribute is declared (but not 
> necessarily defined).
> 
> e.g. I want to tell the difference between the following:
> 
> <myclass>
> <attribute name="myAttribute" />
> </myclass>
> 
> <myclass>
> </myclass>
> 
> It's no use testing for undefined, because in the first case, myAttribute 
> _is_ undefined.
> 
> Thanks,
> 
> Antun


Reply via email to