我有2个条件比较2个模型,如果它们存在或不显示不同的消息。 对象this.realEstateProjectCurrentProduct
保持不变,它的属性housingTax
或propertyTax
不同,其他情况保持不变。JavaScript/Angular1 - 重构算法/逻辑条件
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'
}
如何提高这2个条件,因为他们之间有太多的相似之处与Lodash或ECMAScript的2015年例如
上面的代码将永远不会得到第二if语句,因为你在赋值之前的所有返回语句 –