`args` is passed in from the compiler, it is a hash (Object) of the
initial arguments to the constructor (mostly attributes from the LZX
tag). You couldn't be expected to know that.
Even I don't know (off the top of my head) if args is one of these
magic 'inherited hashes' where it is linked by __proto__ to init args
from its superclass. This is important because, if you are trying to
figure out if `args` has a property 'height'.
1) Ideally you would ask `'height' in args`, but the swf runtime does
not support that (yet).
2) If args is a straight hash, not using __proto__ inheritance, then
you can ask `args.hasOwnProperty('height')
3) Or you could use the current idiom `typeof(args.height) !=
'undefined'`, which is not as exact as 1 or 2, but will usually
suffice, and will not give a warning.
Note that in this particular case, you really have to use one of
these three, because `args.height` is allowed to have a value of
`null`. Asking:
if (args['height']) ...
(which will not give a warning if the height property does not exist)
will confuse there not being a height property with the height
property being `null`. Also, Jim has endorsed changing `[]` and
`typeof` to warn on access to non-existent properties, so you should
ideally use 1 or 2 when fixing these types of bugs (unless you can
ensure that the property will always have a value, which you can't do
in the case of args).
[I hope this is the most complex case you run into! Too bad you hit
is so early on.]
On 2006-05-12, at 06:17 PDT, Philip wrote:
> If a statement like this will trigger a warning, what is the
> correct way to
> fix this problem? Should I look through the code and make sure it is
> initialized to null?
>
> Thanks!
>
> Phil
>
>
>>>> if (args.height)
>>
>> Note that if args.height does not exist or is set to the undefined
>> value, this will still trigger a warning.
>
>
_______________________________________________
Laszlo-dev mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-dev