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.2
 模块化简史
3
这种强制性的分离是有效的,因为它可以保持组件的整齐以及层级的一致。
从开发者的角度看,一致的层级(由模式和外观相似的组件组成)可带来
熟悉感,这种熟悉感让人能够持久地使用它,并且随着时间的推移,开发
人员会越来越熟悉
API
的形态(
shape
)。
由于设计出合适的接口是一件有难度的事情,所以采用一致的
API
形态是
提高生产力的好方法。当我们始终如一地使用相似的
API
形态时,就不必
每次都重新提出新的设计,而且使用者对于你不会每次都重新造轮子的行
为也能感到放心。在接下来的章节中,我们将详细讨论
API
设计。
1.2
 模块化简史
对于
JavaScript
来说,模块化是一个现代概念。在本节中,我们将快速回
顾和总结
JavaScript
世界中模块化发展的里程碑,我们仅介绍主流做法在
JavaScript
历史中的演化,而不会详尽地进行说明。
1.2.1
 
Script
标签和闭包
在早期,
JavaScript
被嵌入到
HTML
<script>
标签中,好一点的情况是把
它封装到专门的脚本文件中调用,所有这些脚本文件都共享一个全局作用
域。
在这些文件或内联脚本中声明的任何变量或绑定(
binding
)都被挂载到全
局的
window
对象上,因此造成了不相关脚本的互相污染,这可能会导致冲
突甚至程序崩溃,因为某个脚本中的变量可能会在无意中覆盖了另一个脚
本所依赖的全局变量
4
1
模块化思维
<script>
var initialized = false
if (!initialized) {
init() ...
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