- Mastering JavaScript Design Patterns
- Simon Timms
- 238字
- 2021-08-05 17:14:58
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 small code files to work with, and reducing the number of requests to the server from the browser.
- What's New in TensorFlow 2.0
- Monitoring Elasticsearch
- 重學(xué)Java設(shè)計(jì)模式
- Unity 5.x By Example
- 算法訓(xùn)練營(yíng):提高篇(全彩版)
- Learning DHTMLX Suite UI
- 區(qū)塊鏈技術(shù)與應(yīng)用
- Access 2010中文版項(xiàng)目教程
- C++語(yǔ)言程序設(shè)計(jì)
- Python開(kāi)發(fā)基礎(chǔ)
- 交互式程序設(shè)計(jì)(第2版)
- Android編程權(quán)威指南(第4版)
- Software-Defined Networking with OpenFlow(Second Edition)
- Building a Media Center with Raspberry Pi
- 算法訓(xùn)練營(yíng):海量圖解+競(jìng)賽刷題(入門篇)