简体   繁体   English

可以将JavaScript分解为Visual Studio中的区域吗?

[英]Can JavaScript be broken into regions in Visual Studio?

C# code can be separated into regions by using the #region and #endregion tags. 可以使用#region和#endregion标记将C#代码分隔为多个区域。

Can the same be done for JavaScript code ? 可以为JavaScript代码完成相同的操作吗? I have a file with some 1100 lines and it's getting hard to manage it. 我有一个1100行的文件,很难管理它。

It sounds like you're looking for the Web Essentials extension for Visual Studio 2010. 听起来您正在寻找Visual Studio 2010的Web Essentials扩展

From the features list: 从功能列表:

在此输入图像描述

However, it also might be best to start to break apart your JavaScript files into smaller files, or separate modules. 但是,最好将JavaScript文件拆分为较小的文件或单独的模块。 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 . 如果需要,可以使用诸如YUI Compressor之类的构建工具再次组合这些文件。

Even if you would have #region and #endregion for Javascript this would not solve your problem. 即使你有#region和#endregion for Javascript,这也无法解决你的问题。 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. 您应该专注于将整个逻辑分离为单独的文件,并使每个JS文件负责某项工作。 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 我建议阅读这本书(尽管它并不严格关于JS,但关于写作一般): http ://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM