Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something similar to C# regions in JavaScript? Visual Studio 2017

I am doing work for somebody who would like their JavaScript library organized into categories: CRUD functions, Form functions, etc. They really like the utility of regions in C# and are asking for this in their JavaScript file. Any suggestions? I am using Visual Studio 2017 and Team Foundation Server.

like image 658
Michael Drum Avatar asked Sep 17 '17 19:09

Michael Drum


People also ask

What language is most similar to C?

Javascript has a reasonably C-like syntax, and it's a very popular language. Javascript has a lot of quirks, but it has one powerful similarity to C - it's simple.

Is there an alternative to C?

The best alternative is Java. It's not free, so if you're looking for a free alternative, you could try C++ or Rust. Other great apps like C (programming language) are Go (Programming Language), C#, Lua and Perl.

What languages are similar to C?

These languages are C++ (also known as C with classes), C#, Python, Java, JavaScript, Perl, PHP, Verilog, D, Limbo and C shell of Unix etc. Every language uses C language in variable capacity.

Is C++ very similar to C?

C++ is a superset of C, so both languages have similar syntax, code structure, and compilation. Almost all of C's keywords and operators are used in C++ and do the same thing. C and C++ both use the top-down execution flow and allow procedural and functional programming.


3 Answers

For VS 2019, Microsoft has fully implemented regions for Javascript, they work exactly they way they work in C#, only, you have to preface the beginning and end of the regions as comments, for example:

//#region My Region
function foo(){
  *//code*
}
//#endregion

For anything prior to VS 2019, See Michael Drum's answer. His shortcut also works in VS 2019.

like image 81
Robert Avatar answered Oct 27 '22 00:10

Robert


The link in the given answer is broken. Here is a great plugin which I use daily and no issue so far:

Java Script Regions

PS: Not tried this with other than VS 2017

enter image description here

like image 39
curiousBoy Avatar answered Oct 27 '22 00:10

curiousBoy


Select the code you want to compress. Press Ctrl + M + H. That code will now be collapsible. For readability, comment above the "region" to give it a name.

Source: http://blog.degree.no/2013/05/define-a-region-in-javascript-files-visual-studio-2010-2012/

like image 33
Michael Drum Avatar answered Oct 27 '22 00:10

Michael Drum