这个好像是真的。我怎样才能将其减少为一个 if 语句?
let combined = true;
if(earlyCallback){
combined = self.allChildBlocksCompleted;
}
if (self.parent && combined) { // I want to put everything here
}
这是正确的吗?
if(self.parent || (earlyCallback && self.allChildBlocksCompleted)){
}
我认为这是正确的,但我现在不能说。
最佳答案
我更喜欢像下面那样做:
if (self.parent && (earlyCallback ? self.allChildBlocksCompleted : true )) { }
关于javascript - 将代码逻辑简化为一行表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46419602/