【发布时间】:2016-06-14 14:33:38
【问题描述】:
有人知道实现以下目标的更简洁/优雅的方式吗?
A = B if B?
谢谢。
编辑:
我正在寻找只引用 A 和 B 一次的解决方案。并将编译为if (typeof B !== "undefined" && B !== null) { A = B; }
或其他类似的东西。
有这个简短的帮助使以下内容更具可读性:someObject[someAttribute] = (someOtherObject[someOtherAttribute] if someOtherObject[someOtherAttribute]?)
这就是我提出问题的动机。
【问题讨论】:
-
对我来说已经非常优雅了?你还有什么期待?
-
A 和 B 的东西只被引用一次。抱歉,我最初的问题确实缺乏特异性。
-
最佳: Coffeescript:
a = b ? aJavascipt:var a; a = typeof b !== "undefined" && b !== null ? b : a;好 Coffeescript:A = B if B?Javascript:var A; if (typeof B !== "undefined" && B !== null) { A = B; }我会选择“mu太短了”的答案。
标签: coffeescript