I have followed this discussion with great attention and even greater 
head-scratching, trying to figure out what, if anything I should add to 
the Developer's Guide about checking for the existence of properties.

It seems to me that the first sentence of Tucker's message, below, is 
basically all I need to say on the topic. Any deviations from "good 
software engineering practice" being beyond the scope of OpenLaszlo 
docs.

If I should say anything else, please let me know what it is.

Thanks,

jrs
On May 12, 2006, at 1:33 PM, P T Withington wrote:

> I think it is best to define all your properties, rather than relying
> on it not being an error to reference an undefined property.  It's
> good software engineering, and I think we will see Javascript tending
> in a direction where you have to give up this kind of dynamicity for
> performance anyways (IOW, it will cost you more to reference a non-
> existent property than a property declared with a default).
>
> Remember also that many times you can set a default value on the
> class prototype and get it 'for free' in all the instances of the 
> class.
>
> On 2006-05-12, at 09:19 PDT, Philip Romanik wrote:
>
>> Thanks Tucker!
>>
>> I have a related question. When I find object properties that are
>> not defined, I am giving them an initial value of null. This
>> eliminates the problem with undefined and allows me to do this,
>>
>>     if (this.somevariable)
>>         ...
>>
>> in the code. This makes cleaner code but it does potentially define
>> a lot of properties that are not often used.
>>
>> Any advice?
>>
>> Phil
>>
>>
>>> `in` is not yet supported in the SWF runtime.
>>>
>>> `hasOwnProperty` is supported in both runtimes.  When we use `new
>>> Object` or literal objects to represent hash tables, best
>> practice is
>>> to use `hasOwnProperty` to detect the presence of a key in the
>>> table.  (Consider a table that might have the keys `toString`,
>>> `constructor`, etc. which are inherited by all objects:  only
>>> `hasOwnProperty` can tell if those keys are in the table or not.)
>>>
>>> So my recommendation to Phil is to use `hasOwnProperty` anywhere it
>>> is clear that we are using an object as a hash table and only resort
>>> to `[]` or `typeof` if it is not clear.
>>
>
> _______________________________________________
> Laszlo-dev mailing list
> [email protected]
> http://www.openlaszlo.org/mailman/listinfo/laszlo-dev

_______________________________________________
Laszlo-dev mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-dev

Reply via email to