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

  • JavaScript:Moving to ES2015
  • Ved Antani Simon Timms Narayan Prusty
  • 240字
  • 2021-07-09 19:07:47

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.

主站蜘蛛池模板: 安岳县| 柘城县| 开封市| 山阴县| 修水县| 辉南县| 九江县| 平昌县| 岑溪市| 米脂县| 庆城县| 怀来县| 汉中市| 绥芬河市| 鸡泽县| 科技| 隆德县| 留坝县| 石家庄市| 鹤峰县| 民县| 翼城县| 大姚县| 舟山市| 常宁市| 黑水县| 灵台县| 锦州市| 云龙县| 石柱| 西乌珠穆沁旗| 屏东县| 云浮市| 嘉禾县| 大埔县| 石城县| 龙泉市| 闻喜县| 平遥县| 塔城市| 博野县|