how to implement regions/code collapse in javascript

后端 未结 17 1591
灰色年华
灰色年华 2020-11-28 21:01

How can you implement regions a.k.a. code collapse for JavaScript in Visual Studio?

If there are hundreds of lines in javascript, it\'ll be more understandable using

相关标签:
17条回答
  • 2020-11-28 21:35

    This is now natively in VS2017:

    //#region fold this up
    
    //#endregion
    

    Whitespace between the // and # does not matter.

    I do not know what version this was added in, as I cannot find any mention of it in the changelogs. I am able to use it in v15.7.3.

    0 讨论(0)
  • 2020-11-28 21:36

    Not only for VS but nearly for all editors.

    (function /* RegionName */ () { ... })();

    Warning: has disadvantages such as scope.

    0 讨论(0)
  • 2020-11-28 21:37

    By marking a section of code (regardless of any logical blocks) and hitting CTRL + M + H you’ll define the selection as a region which is collapsible and expandable.

    0 讨论(0)
  • 2020-11-28 21:42

    Good news for developers who is working with latest version of visual studio

    The Web Essentials are coming with this feature .

    Check this out

    Note: For VS 2017 use JavaScript Regions : https://marketplace.visualstudio.com/items?itemName=MadsKristensen.JavaScriptRegions

    0 讨论(0)
  • 2020-11-28 21:44

    For VS 2019, this should work without installing anything:

        //#region MyRegion1
    
        foo() {
    
        }
    
        //#endregion
    
        //#region MyRegion2
    
        bar() {
    
        }
    
        //#endregion
    
    0 讨论(0)
  • 2020-11-28 21:46

    For visual studio 2017.

        //#region Get Deactivation JS
        .
        .
        //#endregion Get Deactivation JS
    

    This was not working earlier so I downloaded extension from here

    Extension Name(JavaScript Regions) By Mads Kristensen

    0 讨论(0)
提交回复
热议问题