问题:
Is there a null
-safe property access (null propagation / existence) operator in ES6 (ES2015/JavaScript.next/Harmony) like ?.
在 ES6 (ES2015/JavaScript.next/Harmony) 中是否有一个null
属性访问(null 传播/存在)运算符,比如?.
in CoffeeScript for example?例如在CoffeeScript中? Or is it planned for ES7?还是计划用于 ES7?
var aThing = getSomething()
...
aThing = possiblyNull?.thing
This will be roughly like:这将大致如下:
if (possiblyNull != null) aThing = possiblyNull.thing
Ideally the solution should not assign (even undefined
) to aThing
if possiblyNull
is null
理想情况下,解决方案不应该分配(甚至undefined
),以aThing
如果possiblyNull
是null
解决方案:
参考一: https://en.stackoom.com/question/2AqqE参考二: https://stackoom.com/question/2AqqE