I wrote a code before, the general logic is as follows
function control (type) {
if (type == 1){
console.log("功能1");
}else {
console.log("功能2");
}
}
Because the previous business logic requirements only have function 1 and function 2, function 1 will be executed when control(1) is executed, and function 2 will be executed for the rest
Now the requirements have been changed and a function 3 needs to be added because the previous logic was complicated and I did not want to change the previous logic nesting
function control (type) {
if (type == 1){
console.log("功能1");
}else {
console.log("功能2");
}
if(type == 3){
console.log("功能3");
}
}
control(3);
In this case, function 3 and function 2 are executed together. How can I only execute function 3
No need to switch case
PHP中文网2017-06-26 11:00:12
if (type == 1){
console.log("function 1");
}else if(type == 3) {
console.log("function 3");
}
else{
console.log("Function 2");
}
三叔2017-06-26 11:00:12
function control (type) {
if (type == 1){
console.log("功能1");
} else if (type == 3){
console.log("功能3");
} else {
console.log("功能2");
}
}
control(3);