ES6 / ES2015中的空安全属性访问 [英] null-safe property access in ES6 / ES2015
本文介绍了ES6 / ES2015中的空安全属性访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在ES6 / ES2015 / JavaScript.next / Harmony中是否有一个安全的属性访问(null传播/存在)运算符,例如 CoffeeScript ?
Is there a null-safe property access (null propagation / existence) operator in ES6 / ES2015 / JavaScript.next / Harmony like in CoffeeScript for example? Or is it planned for ES7?
aThing = possiblyNull?.thing
这或多或少地类似于:
if (possiblyNull != null) aThing = possiblyNull.thing
当它不是 rvalue
:
(possiblyNull != null)? possiblyNull.thing : undefined
推荐答案
您可以在JavaScript中使用 lodash#get 或类似的操作。
No. You may use lodash#get or something like that for this in JavaScript.
这篇关于ES6 / ES2015中的空安全属性访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文