简体   繁体   中英

Shortband for switch..case doesn't work

I am clueless why this piece of code doesn't work:

switch (Category.getValue()) {
    case 1: () => { for (var i = 0; i < 12; i++) OptionSet.addOption(options[i]); }; break;
    default: () => { OptionSet.clearOptions(); }; break;
}

It hits case 1: , but then instead of doing loop it just quits switch statement.

With your code () => {} You are essentially defining an anonymous function without assigning or calling it. You can remove that part from the code and it will work. Example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM