This trick seems to me more elegant (using an array and indexOf):
var conflicts = ['CONFLICT-GROUP-GENERAL',
'CONFLICT-USER-GENERAL',
'CONFLICT-FORM-GENERAL',
'CONFLICT-PROJECT-GENERAL',
'CONFLICT-TEMPLATE-GENERAL'];
if (conflicts.indexOf(err.code) !== -1) {
doSomething();
}
If you are using ES7 then you can use includes() instead of indexOf
. This will be more "expressive":
var conflicts = ['CONFLICT-GROUP-GENERAL',
'CONFLICT-USER-GENERAL',
'CONFLICT-FORM-GENERAL',
'CONFLICT-PROJECT-GENERAL',
'CONFLICT-TEMPLATE-GENERAL'];
if (conflicts.inclues(err.code)) {
doSomething();
}
Note that includes()
will not be suported by all browsers.
EDIT:
Another alternative: Using a switch. This way:
switch (err.code) {
case 'CONFLICT-GROUP-GENERAL',:
case 'CONFLICT-USER-GENERAL',:
case 'CONFLICT-FORM-GENERAL',:
case 'CONFLICT-PROJECT-GENERAL',:
case 'CONFLICT-TEMPLATE-GENERAL':
doSomething();
break;
}
The code above will execute the doSomething()
function when err.code
is equal to one of specified strings in each case
.