是否可以使用可选链接 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining运算符位于赋值的左侧=
在 JavaScript 中?
const building = {}
building?.floor?.apartment?.number = 3; // Is this possible?
有一个提案(第一阶段)支持它:https://github.com/nicolo-ribaudo/proposal-optional-chaining-assignment https://github.com/nicolo-ribaudo/proposal-optional-chaining-assignment
这是不可能的,抱歉。
为了获得规范的答案:MDN 文档对此没有明确说明,但您可以阅读GitHub 中提案的自述文件 https://github.com/tc39/proposal-optional-chaining了解更多信息。它says https://github.com/tc39/proposal-optional-chaining#not-supported:
尽管有一些用例,但不支持以下内容;看问题 #18 https://github.com/tc39/proposal-optional-chaining/issues/18供讨论:
在链接的问题中有评论1 https://github.com/tc39/proposal-optional-chaining/issues/18#issuecomment-331952897:
好的,似乎该线程中有一个粗略的协议,即不要在第一次迭代中执行写入操作。
and 2 https://github.com/tc39/proposal-optional-chaining/issues/18#issuecomment-343926065:
我们在 TC39 上也讨论过这个问题,委员会似乎对添加这个功能不太感兴趣。
所以我想这不太可能很快发生。
希望有帮助;祝你好运!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)