19

I’m looking for equivalent functionality to C# regions in javascript

C# syntax

#region RegionName

public static void MyFunction()
{
    [mycode]
}

#endregion

This allows me to “collapse” my code in my .js file with Visual Studio and make it a little more manageable.

Anybody got any ideas?

Brandon
  • 68,708
  • 30
  • 194
  • 223
seanbrant
  • 1,347
  • 3
  • 13
  • 15

7 Answers7

53

If it need for collapse the java script code then you may select the code and press

Ctrl + M + H

It will collapse the selected code.

17

Microsoft now has an extension for VS2010 that provides this functionality:

JScript Editor Extensions

BrianFinkel
  • 2,687
  • 3
  • 26
  • 28
13

This feature can be installed in Visual Studio 2012 with the help of Web Essentials plugin.

EDIT:

To do an actual region you can use:

//#region MyRegion
function Example() {

}
//#endregion

The plugin can be downloaded here: Web Essentials 2012, Web Essentials for 2010

6

Take a look at this article, which implements the #region directives in js files using macros.

Brandon
  • 68,708
  • 30
  • 194
  • 223
5

For Visual Studio 2012, you can use this extension: http://visualstudiogallery.msdn.microsoft.com/4be701d8-af03-40a4-8cdc-d2add5cde46c

Johnny Oshika
  • 54,741
  • 40
  • 181
  • 275
1

This is the best one (I've tried them all):

http://visualstudiogallery.msdn.microsoft.com/0696ad60-1c68-4b2a-9646-4b5f4f8f2e06/view/Discussions/1

RedAces
  • 319
  • 1
  • 3
  • 16
1

There is a javascript outlining extension for VS 2010 here http://jsoutlining.codeplex.com/documentation it works great for me

scepak
  • 73
  • 1
  • 2
  • 9