`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.
On 2006-05-12, at 08:29 PDT, Jim Grandy wrote:
>
> On May 12, 2006, at 8:21 AM, P T Withington wrote:
>
>> Yes, but they are idioms. I thought you endorsed my suggestion
>> that they be phased out in favor of the standards `in` and
>> `hasOwnProperty`.
>>
> I do endorse that suggestion, but wasn't clear whether either was
> supported yet. Can you clarify what the current implemented best
> practice is?
>> At the very least, Phil should try _not_ to introduce any more
>> uses of `[]` or `typeof` as a way to test for the existence of a
>> property, since I assume some day we will want to warn on those too?
>>
> Agreed, assuming `in` is available to us. I remember a checkin from
> you, but don't remember whether it completed the feature.
>> On 2006-05-12, at 08:05 PDT, Jim Grandy wrote:
>>
>>> But that's what we're doing for now, right? If I parse out your
>>> full explanation ("How to determine if a property exists"), I
>>> think that's one of the two idioms you are referring to at the
>>> end of the message :-)
>>>
>>>> By extension, the compiler ought not warn if you ask `foo.bar
>>>> instanceof <class>`, or as you suggest `foo.bar == void 0`[1]. But
>>>> that just creates more idioms we will eventually need to fix. I
>>>> suggest we stick with the two idioms we have for now and elevate
>>>> the
>>>> priority of LPP-969.
>>>
>>> On May 12, 2006, at 8:00 AM, P T Withington wrote:
>>>
>>>> We need to come up with a policy on this.
>>>>
>>>> On 2006-05-12, at 07:30 PDT, Jim Grandy wrote:
>>>>
>>>>> The idiom we're using now is args['height'], which (by special
>>>>> arrangement with our compiler) doesn't warn on null.
>>>>>
>>>>> jim
>>>>>
>>>>> On May 12, 2006, at 6:20 AM, Philip Romanik 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
>>>>>
>>>>
>>>
>>
>
_______________________________________________
Laszlo-dev mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-dev