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
109
5
模块化模式与实践
本章将介绍一些最新的语言特性,以及如何利用这些特性减少应用程序的
复杂性,同时还将分析具体的编码方式和规范,以帮助你开发简单的替代
方案来解决复杂的问题。
5.1
 利用现代
JavaScript
如果能够合理使用最新的
JavaScript
语言特性,可以有效减少程序代码量,
最主要是能够绕开语言本身的限制。也就是说,当消除了样板文件和重复
代码后,我们在阅读一段代码的过程中能提取出大量有价值的信息。
5.1.1
 模板字面量
ES6
之前,
JavaScript
社区提出了
6
种方法来实现多行字符串:从使用“
\
转义字符或者“
+
”算术运算符来连接字符串,到使用
Array#join
或在函数
中注释的字符串表示形式,所有这些只是为了提供对多行字符串的支持。
110
5
模块化模式与实践
此外,虽然无法直接在字符串中插入变量,但是将变量与字符串连接起来
却很容易
'Hello ' + name + ', I\'m Nicolás!'
ES6
中引入了模板字面量(
template literal
),这种语法使用原生的语言特
性来解决多行字符串问题,无须再使用其他
hack
手段。
与字符串不同,有了模板字面量,我们可以使用改进的语法来插入表达式,
这样做涉及的转义操作更少,这要归功于所用的反引号而不是在英文中出 ...
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