Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #38394

Re: check for obj nested prop

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: check for obj nested prop
Date Sat, 09 May 2020 03:09:00 +0100
Organization A noiseless patient Spider
Lines 26
Message-ID <873689yi4j.fsf@bsb.me.uk> (permalink)
References <C9udnTlJHfCQbSnDnZ2dnUU7-U3NnZ2d@westnet.com.au> <87pnbeycrm.fsf@bsb.me.uk> <11518358.O9o76ZdvQC@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain
Injection-Info reader02.eternal-september.org; posting-host="8b3d9a98c74a7c42702bb3ceb61230f2"; logging-data="16333"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19u8vX1PV/AMyNvwWEniMUtZFqP9FLrw1k="
Cancel-Lock sha1:gdg9YmNC5GSfuWl4ewNxWJwX8S8= sha1:+i45B7HhwmKueOmPP87ehPusPsM=
X-BSB-Auth 1.33e17b8d2c73faabee52.20200509030900BST.873689yi4j.fsf@bsb.me.uk
Xref csiph.com comp.lang.javascript:38394

Show key headers only | View raw


Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:

> Ben Bacarisse wrote:
>
>> Andrew Poulos <ap_prog@hotmail.com> writes:
>>> so I end up doing
>>>
>>> if (a && a.b && a.b.c && a.b.c.d)
>> <cut>
>>> Is there a way to get the check value of an object's nested property
>>> without first having to test for all the ascendant properties?
>> 
>>   if (try {obj.a.b.c.d} catch {})
>> 
>> might do what you want.
>
> This is *obviously* syntactically invalid;

Yes, wishful thinking.  You'd need a function call and a return:

  if ( (()=>{ try {return obj.a.b.c.d} catch {} })() ) ...

which makes it rather clumsy.

-- 
Ben.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

check for obj nested prop Andrew Poulos <ap_prog@hotmail.com> - 2020-05-08 15:37 +1000
  Re: check for obj nested prop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-05-08 10:52 +0100
    Re: check for obj nested prop Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-05-09 00:26 +0200
      Re: check for obj nested prop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-05-09 03:09 +0100
        Re: check for obj nested prop Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-05-12 09:28 +0200
          Re: check for obj nested prop Julio Di Egidio <julio@diegidio.name> - 2020-05-12 04:01 -0700
    Exception handling (was: check for obj nested prop) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-05-09 03:46 +0200
  Re: check for obj nested prop JJ <jj4public@vfemail.net> - 2020-05-08 17:18 +0700
  Re: check for obj nested prop Julio Di Egidio <julio@diegidio.name> - 2020-05-08 03:53 -0700
  Re: check for obj nested prop James Kirk <noneya.invalid@gmail.com> - 2020-05-08 11:00 -0400
  Re: check for obj nested prop Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-05-09 00:19 +0200
    Re: check for obj nested prop Julio Di Egidio <julio@diegidio.name> - 2020-05-12 04:04 -0700
      Re: check for obj nested prop luserdroog <luser.droog@gmail.com> - 2020-05-12 07:59 -0700
  Re: check for obj nested prop "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-05-12 14:17 -0700
    Re: check for obj nested prop Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-05-13 02:46 +0200
    Re: check for obj nested prop Andrew Poulos <ap_prog@hotmail.com> - 2020-05-13 13:08 +1000
      Re: check for obj nested prop "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-05-13 12:30 -0700

csiph-web