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

Henry Minsky henry.minsky at gmail.com
Fri Mar 21 07:26:32 PDT 2008


OK, since I'm doing some merging of code in LzNode and LzView,  I'll remove
superfluous  " 'foo' in bar "'s when I encounter them.




On Fri, Mar 21, 2008 at 9:23 AM, P T Withington <ptw at pobox.com> wrote:

> 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
>
>


-- 
Henry Minsky
Software Architect
hminsky at laszlosystems.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.openlaszlo.org/pipermail/laszlo-dev/attachments/20080321/0099fdcd/attachment-0001.html


More information about the Laszlo-dev mailing list