<div dir="ltr">?. does not *compose* though, and a standard way to retrieve a path is needed in JSON Pointer too [1]<div><br></div><div>I've personally used similar approach in various cases, and old libraries like Ext.JS used to</div><div>`Function("this." + path.join('.')).call(target)` to retrieve a path in a speedy way.</div><div><br></div><div>Beside the "array of string" bit, which is limited if we think nested Arrays and/or Symbols as properties, I think a standard way to retrieve a path would be beneficial in various cases.</div><div><br></div><div>Just my 2 cents.</div><div><br><div>[1] <a href="https://tools.ietf.org/html/rfc6901">https://tools.ietf.org/html/rfc6901</a></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 15, 2018 at 11:29 PM, Sebastian Malton <span dir="ltr"><<a href="mailto:sebastian@malton.name" target="_blank">sebastian@malton.name</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="background-color:rgb(255,255,255);background-image:initial;line-height:initial"><div id="m_8602197017506256461response_container_BBPPID" style="outline:none;font-size:initial;font-family:"Calibri","Slate Pro",sans-serif,"sans-serif"" dir="auto"> <div name="BB10" dir="auto" style="width:100%;padding:initial;font-size:initial;text-align:initial;background-color:rgb(255,255,255)"> This would be redundant because of the `?.` operator once it gets merged</div>                                                                                                                                      <div name="BB10" dir="auto" style="width:100%;padding:initial;font-size:initial;text-align:initial;background-color:rgb(255,255,255)"> <br style="display:initial"></div>                            <div id="m_8602197017506256461blackberry_signature_BBPPID" name="BB10" dir="auto">     <div name="BB10" dir="auto" style="padding:initial;font-size:initial;text-align:initial;background-color:rgb(255,255,255)"><p dir="ltr">Sebastian Malton </p></div> </div></div><div id="m_8602197017506256461_original_msg_header_BBPPID" dir="auto">                                                                                                                                             <table width="100%" style="background-color:white;border-spacing:0px;display:table;outline:none"><tbody><tr><td colspan="2" style="padding:initial;font-size:initial;text-align:initial;background-color:rgb(255,255,255)">                           <div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in;font-family:Tahoma,"BB Alpha Sans","Slate Pro";font-size:10pt">  <div id="m_8602197017506256461from"><b>From:</b> <a href="mailto:vikashagrawal1990@gmail.com" target="_blank">vikashagrawal1990@gmail.com</a></div><div id="m_8602197017506256461sent"><b>Sent:</b> February 15, 2018 5:27 PM</div><div id="m_8602197017506256461to"><b>To:</b> <a href="mailto:es-discuss@mozilla.org" target="_blank">es-discuss@mozilla.org</a></div><div id="m_8602197017506256461subject"><b>Subject:</b> Proposal: Object.path([ ... ], defaultValue)</div></div></td></tr></tbody></table> <br> </div><div><div class="h5"><div name="BB10" dir="auto" style="background-image:initial;line-height:initial;outline:none"><div dir="ltr">Hello Everyone, <div><div><br></div><div>It is a lot of times that we see `x is not a property of undefined` and to solve this we have to resort to &&, something like -> data && <a href="http://data.childData" target="_blank">data.childData</a> && <a href="http://data.childData.innerDataArray" target="_blank">data.childData.innerDataArray</a> && <span style="color:rgb(34,34,34);font-family:'arial',sans-serif;font-size:small;font-style:normal;font-weight:400;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inline"><a href="http://data.childData.innerDataArray.length" target="_blank">data.childData.<wbr>innerDataArray.length</a> > 0 whiich is quiet verbose. </span></div></div><div><span style="color:rgb(34,34,34);font-family:'arial',sans-serif;font-size:small;font-style:normal;font-weight:400;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inline"><br></span></div><div><span style="color:rgb(34,34,34);font-family:'arial',sans-serif;font-size:small;font-style:normal;font-weight:400;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inline">I suggest, we should add a utility method like <a href="http://Object.path" target="_blank">Object.path</a>, which takes an array of strings and returns the value from a given nested object. Also, this can take a second argument which will be a default value if not found. </span></div><div><span style="color:rgb(34,34,34);font-family:'arial',sans-serif;font-size:small;font-style:normal;font-weight:400;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inline"><br></span></div><div>This is inspired by path and pathOr as implemented in <a href="http://ramdajs.com/docs/#path" target="_blank">http://ramdajs.com/docs/#path</a></div><div><br></div><div>Regards</div><div>~Vikash</div></div>
</div></div></div></div><br>______________________________<wbr>_________________<br>
es-discuss mailing list<br>
<a href="mailto:es-discuss@mozilla.org">es-discuss@mozilla.org</a><br>
<a href="https://mail.mozilla.org/listinfo/es-discuss" rel="noreferrer" target="_blank">https://mail.mozilla.org/<wbr>listinfo/es-discuss</a><br>
<br></blockquote></div><br></div>