官术网_书友最值得收藏!

Best practices and troubleshooting

In an ideal world everybody would get to work on greenfield projects where they can put in standards right from the get go. However that isn't the case. Frequently you may find yourself in a situation where you have a bunch of non-modular JavaScript code as part of a legacy system.

In these situations it may be advantageous to simply ignore the non-modular code until there is an actual need to upgrade it. Despite the popularity of JavaScript, much of the tooling for JavaScript is still immature making it difficult to rely on a compiler to find errors introduced by JavaScript refactoring. Automatic refactoring tools are also complicated by the dynamic nature of JavaScript. However, for new code, proper use of modular JavaScript can be very helpful to avoid namespace conflicts and improve testability.

How to arrange JavaScript is an interesting question. From a web perspective I have taken the approach of arranging my JavaScript in line with the web pages. So each page has an associated JavaScript file, which is responsible for the functionality of that page. In addition, components which are common between pages, say a grid control, are placed into a separate file. At compile time all the files are combined into a single JavaScript file. This helps strike a balance between having a small code file with which to work and reducing the number of requests to the server from the browser.

主站蜘蛛池模板: 泗水县| 丰原市| 临桂县| 泸定县| 黄平县| 丰原市| 仁寿县| 津市市| 汝阳县| 小金县| 澄江县| 剑川县| 沐川县| 诏安县| 荣昌县| 阳东县| 天津市| 自治县| 峡江县| 渭南市| 溆浦县| 永川市| 海宁市| 长治县| 密山市| 布拖县| 扬中市| 荥经县| 绥宁县| 板桥市| 延庆县| 金平| 舒兰市| 大名县| 周宁县| 嘉定区| 封丘县| 九龙城区| 阿勒泰市| 桐庐县| 徐闻县|