MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/7ytegt/optional_chaining_may_be_coming_to_javascript/dummr1p/?context=3
r/javascript • u/gregbaugues • Feb 20 '18
100 comments sorted by
View all comments
1
Cool!
For anyone wanting to use this today and is already using lodash or underscore, use the _.get method
_.get(object, 'path.to[0][1].deeply.nested.freakin.item', optionallyDefaultValue)
https://lodash.com/docs#get
4 u/bart2019 Feb 20 '18 Meh.That means the code has to parse the path, every single time, and then, traverse it. 1 u/DukeBerith Feb 22 '18 Nah.Lodash's stuff tends to be memoised, and a quick skim in the source code shows that the path gets computed once and stored for future reuse. It only is parsed every time if that path is dynamic and is different every single time. 1 u/bart2019 Feb 22 '18 It still needs a loop.
4
Meh.
That means the code has to parse the path, every single time, and then, traverse it.
1 u/DukeBerith Feb 22 '18 Nah.Lodash's stuff tends to be memoised, and a quick skim in the source code shows that the path gets computed once and stored for future reuse. It only is parsed every time if that path is dynamic and is different every single time. 1 u/bart2019 Feb 22 '18 It still needs a loop.
Nah.
Lodash's stuff tends to be memoised, and a quick skim in the source code shows that the path gets computed once and stored for future reuse. It only is parsed every time if that path is dynamic and is different every single time.
1 u/bart2019 Feb 22 '18 It still needs a loop.
It still needs a loop.
1
u/DukeBerith Feb 20 '18
Cool!
For anyone wanting to use this today and is already using lodash or underscore, use the _.get method
_.get(object, 'path.to[0][1].deeply.nested.freakin.item', optionallyDefaultValue)https://lodash.com/docs#get