简体   繁体   中英

Can JavaScript be broken into regions in Visual Studio?

C# code can be separated into regions by using the #region and #endregion tags.

Can the same be done for JavaScript code ? I have a file with some 1100 lines and it's getting hard to manage it.

It sounds like you're looking for the Web Essentials extension for Visual Studio 2010.

From the features list:

在此输入图像描述

However, it also might be best to start to break apart your JavaScript files into smaller files, or separate modules. That way, you can only include the code relevant to a specific page. If need be, those files can be combined again using a build tool such as YUI Compressor .

Even if you would have #region and #endregion for Javascript this would not solve your problem. You should focus on separating the whole logic into separate files and make that each JS file is responsible for a certain piece of work. Believe me - this will considerably improve the readability of your code and make it much more maintainable. I recommend to read this book (although it is not stricly about JS, but about writing in general): http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

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