Inside a JavaScript switch
instruction, different case
(s) may contain much code. Therefore it could be useful to collapse (fold) the code for cases other than the one I am working on.
I use Netbeans. How do I do that?
Inside a JavaScript switch
instruction, different case
(s) may contain much code. Therefore it could be useful to collapse (fold) the code for cases other than the one I am working on.
I use Netbeans. How do I do that?
Previously unknown to me, but very handy!
Put braces around the code that is inside the case: Netbeans will display the fold/unfold symbol then you can proceed as usual.
switch (kNumCell)
{
case "0":
{
// code comes here
}
break;
// …
}
The simple solution is adding curly braces around your case statement:
switch (num){
case 1: {
//Do something
break;
}
default: {
//Do something
break;
}
}
The more complex solution is to reconfigure code folding to for JavaScript in general: Tools > Options > Editor > Folding > Language >, then select JavaScript.
You can simply add a custom Surround with Code folding suggestion on code selection, so you can fold any part of code you want. Here is a tutorial.