【发布时间】:2015-12-29 01:09:07
【问题描述】:
如果我在 JavaScript 中有这样的语句:
if(!me.a || !me.b || !me.c) {
// I want to know which not was matched here
}
我如何知道在范围内匹配了哪个条件?有没有魔算子?
【问题讨论】:
标签: javascript scope conditional
如果我在 JavaScript 中有这样的语句:
if(!me.a || !me.b || !me.c) {
// I want to know which not was matched here
}
我如何知道在范围内匹配了哪个条件?有没有魔算子?
【问题讨论】:
标签: javascript scope conditional
嗯,一种方法是 && 每个条件的标识符并检查结果。
var result = (!me.a && 1) || (!me.b && 2) || (!me.c && 3);
if(result) {
// if result is 1, then !me.a is true
// if result is 2, then !me.b is true and !me.a is false
// if result is 3, only !me.c is true
}
【讨论】: