Path: csiph.com!3.eu.feeder.erje.net!feeder.erje.net!news.albasani.net!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: check for obj nested prop Date: Sat, 09 May 2020 00:19:15 +0200 Organization: PointedEars Software (PES) Lines: 39 Message-ID: <2530230.mvXUDI8C0e@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: news.albasani.net SeEyDqu3GWdkTi965NTobIpRxn4pcMWK9HZQTvQ8dJXvXb746FFtaXchnL8EBK27+omw5tULeWNzJ9VhxhExrAJvz/V972mCA5w3s1I8ZD9AgamsVV8CdYT22UohnEBb NNTP-Posting-Date: Fri, 8 May 2020 22:19:16 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="0HPVdjcpupBUOIvXVfGEmFDMdW1Qo+gmhdjScqB5M+VVwfmJXuytArXysCzYfBBjMPfatRVBpytM0r2BN0TPxIzoVsHVBt2uyBzhR1du1mckEH8ol3TZ7nV5yjJ/jg+9"; mail-complaints-to="abuse@albasani.net" User-Agent: KNode/4.14.10 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. If I have an object and it get properties added dynamically when I need > to test for a "nested" property and one of the "ascendant" properties > doesn't exist I get an error. For example, > > let obj = {a: 1}; > if (a.b.c.d) // throws error > > so I end up doing > > if (a && a.b && a.b.c && a.b.c.d) > > What happens is that every now and then I get caught when I assume the > properties should exist. > > 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? No. Therefore I had written jsx.object.getFeature(). It has the advantage over the approach presented by “JJ” that it also supports property names that contain a “.”. It basically differs from their approach in that you (can) pass multiple String values as arguments instead of a single String value. (I had the one-string approach first, but ran into problems with “.” in property names.) It can be used like this: if (_getFeature(a, 'b', 'c', 'd')) { // … } -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.