Proposal: Object.path([ ... ], defaultValue)
andrea.giammarchi at gmail.com
Thu Feb 15 22:47:08 UTC 2018
?. does not *compose* though, and a standard way to retrieve a path is
needed in JSON Pointer too 
I've personally used similar approach in various cases, and old libraries
like Ext.JS used to
`Function("this." + path.join('.')).call(target)` to retrieve a path in a
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.
Just my 2 cents.
On Thu, Feb 15, 2018 at 11:29 PM, Sebastian Malton <sebastian at malton.name>
> This would be redundant because of the `?.` operator once it gets merged
> Sebastian Malton
> *From:* vikashagrawal1990 at gmail.com
> *Sent:* February 15, 2018 5:27 PM
> *To:* es-discuss at mozilla.org
> *Subject:* Proposal: Object.path([ ... ], defaultValue)
> Hello Everyone,
> 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 &&
> data.childData && data.childData.innerDataArray && data.childData.
> innerDataArray.length > 0 whiich is quiet verbose.
> I suggest, we should add a utility method like Object.path, 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.
> This is inspired by path and pathOr as implemented in
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss