問題:
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