[Laszlo-dev] Confusing idiom: 'foo' in bar && bar['foo']

P T Withington ptw at pobox.com
Fri Mar 21 06:23:43 PDT 2008


You still don't need the `'foo' in bar`.  If they are testing for non- 
nullness, they can still just say:

   bar['foo'] != null;

The only thing `'foo' in bar` can tell you that `bar['foo']` cannot is  
if bar had a 'foo' property whose value was `undefined`.  So I think  
the `in` test in this idiom is superflous.

On 2008-03-21, at 08:58 EDT, Henry Minsky wrote:
> What if they mean
>
> 'foo' in bar && bar['foo'] != null
>
> ?
>
>
>
> On Fri, Mar 21, 2008 at 8:43 AM, P T Withington <ptw at pobox.com> wrote:
>
>> I'm not sure how this got started:
>>
>>  'foo' in bar && bar['foo']
>>
>> but it is overly-complicated.  If 'foo' is not `in bar`, then
>> `bar['foo']` will evaluate to undefined (and be false), so the first
>> test is superfluous.
>>
>> [Filed as LPP-5660]
>>
>
>
>
> -- 
> Henry Minsky
> Software Architect
> hminsky at laszlosystems.com



More information about the Laszlo-dev mailing list