Skip to Content
精通模块化JavaScript
book

精通模块化JavaScript

by Nicolás Bevacqua
April 2020
Intermediate to advanced
177 pages
1h 45m
Chinese
Publishing House of Electronics Industry
Content preview from 精通模块化JavaScript
1.3
 模块化设计的好处
11
撰写本章时,这个特性在大多数环境中还没有实现,但是很显然
Node.js
在未来支持它
1
Node.js v8.5.0
中,对
ESM
的支持是在一个
--experimental-modules
识后面引入的,前提是我们的模块使用
.mjs
作为文件扩展名。大部分现代
浏览器已经支持
ESM
,因此无须使用标识。
作为
Browserify
的接班人,
Webpack
在很大程度上承担了通用模块打包
器的角色,这归功于其具备的大量新特性。与
Babel
ES6
的情况一样,
Webpack
一直通过它的
import
export
静态声明语句,以及类似
import()
动态函数的表达式来支持
ESM
Webpack
采用
ESM
带来的效益极高,这
在很大程度上要归功于它采用的“代码分割(
code-splitting
)”机制,这种
机制能够将一个应用分成不同的包,以提升首次加载时的性能
2
鉴于
ESM
JavaScript
的原生模块系统(相对于
CJS
),我预计在未来几
年内它会完全主宰模块生态系统。
1.3
 模块化设计的好处
我们已经讨论了这样一个事实:模块化(而不是采用一个共享的全局作用域)
有助于避免变量名中的意外冲突,因为模块的作用域是多样化的。除了解
决冲突之外,文件之间的模块性还减少了我们在处理特定功能时必须注意
的复杂性。因此,我们的开发团队能够专注于手头的任务,工作效率更高。
由于这个原因,
可维护性
maintainability
)或者对代码库进行变更的能力
1
 你可以阅读
Node.js
团队成员
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

数据驱动力:企业数据分析实战

数据驱动力:企业数据分析实战

Carl Anderson
基于Python的智能文本分析

基于Python的智能文本分析

Benjamin Bengfort, Rebecca Bilbro, Tony Ojeda
Lua游戏AI开发指南

Lua游戏AI开发指南

Posts & Telecom Press, David Young

Publisher Resources

ISBN: 9787121387074