Null-safe property access (and conditional assignment) in ES6/2015

后端 未结 10 1200
[愿得一人]
[愿得一人] 2020-11-22 13:00

Is there a null-safe property access (null propagation / existence) operator in ES6 (ES2015/JavaScript.next/Harmony) like ?. in

10条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 13:45

    No, there is no null propagation operator in ES6. You will have to go with one of the known patterns.

    You may be able to use destructuring, though:

    ({thing: aThing} = possiblyNull);
    

    There are many discussions (e.g. this) to add such an operator in ES7, but none really took off.

提交回复
热议问题