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

  • 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.

主站蜘蛛池模板: 田林县| 玛多县| 河津市| 张家港市| 水富县| 上饶市| 二手房| 广州市| 奉节县| 海安县| 栾川县| 文昌市| 岳普湖县| 宜黄县| 黄石市| 明星| 德惠市| 南岸区| 博乐市| 南开区| 海城市| 金寨县| 上高县| 利川市| 修文县| 酒泉市| 喀喇| 吉首市| 凭祥市| 电白县| 塔河县| 宿迁市| 富源县| 若尔盖县| 郯城县| 牙克石市| 永吉县| 黄陵县| 夹江县| 东阿县| 金溪县|