【发布时间】:2017-10-11 09:27:57
【问题描述】:
我有 2 个条件来比较 2 个模型是否存在以显示不同的消息。
对象this.realEstateProjectCurrentProduct保持不变,只是属性housingTax或propertyTax不同,else的大小写保持不变。
if (this.realEstateProjectCurrentProduct.housingTax) {
return this.housingTax = `${this.realEstateProjectCurrentProduct.housingTax} ${this.$translate.instant('currencySymbols.euro')}`
} else {
return this.housingTax = 'No data'
}
if (this.realEstateProjectCurrentProduct.propertyTax) {
return this.propertyTax = `${this.realEstateProjectCurrentProduct.propertyTax} ${this.$translate.instant('currencySymbols.euro')}`
} else {
return this.propertyTax = 'No data'
}
我该如何改善这两个条件,因为它们与 Lodash 或 ecmaScript 2015 有太多相似之处
【问题讨论】:
-
上面的代码永远不会进入第二个 if 语句,因为你在赋值之前有所有的 return 语句
标签: javascript angularjs ecmascript-6 lodash