Jus*_*tin 3 javascript conditional scope
如果我在JavaScript中有一个声明,如:
if(!me.a || !me.b || !me.c) {
// I want to know which not was matched here
}
Run Code Online (Sandbox Code Playgroud)
我怎么知道范围内哪个条件匹配?有没有魔法操作员?
那么,一种方法是&&使用每个条件的标识符并检查结果.
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
}
Run Code Online (Sandbox Code Playgroud)