Table of Contents for
Understanding ECMAScript 6
Close
Version ebook
/
Retour
Understanding ECMAScript 6
by Nicholas C. Zakas
Published by No Starch Press, 2016
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Understanding ECMAScript 6
Contents in Detail
Cover Page
Title Page
Copyright Page
Brief Contents
Contents in Detail
Foreword
Acknowledgments
Introduction
The Road to ECMAScript 6
About This Book
Browser and Node.js Compatibility
Who This Book Is For
Overview
Conventions Used
Help and Support
Chapter 1: Block Bindings
var Declarations and Hoisting
Block-Level Declarations
let Declarations
No Redeclaration
const Declarations
The Temporal Dead Zone
Block Bindings in Loops
Functions in Loops
let Declarations in Loops
const Declarations in Loops
Global Block Bindings
Emerging Best Practices for Block Bindings
Summary
Chapter 2: Strings and Regular Expressions
Better Unicode Support
UTF-16 Code Points
The codePointAt() Method
The String.fromCodePoint() Method
The normalize() Method
The Regular Expression u Flag
Other String Changes
Methods for Identifying Substrings
The repeat() Method
Other Regular Expression Changes
The Regular Expression y Flag
Duplicating Regular Expressions
The flags Property
Template Literals
Basic Syntax
Multiline Strings
Making Substitutions
Tagged Templates
Summary
Chapter 3: Functions
Functions with Default Parameter Values
Simulating Default Parameter Values in ECMAScript 5
Default Parameter Values in ECMAScript 6
How Default Parameter Values Affect the arguments Object
Default Parameter Expressions
Default Parameter TDZ
Working with Unnamed Parameters
Unnamed Parameters in ECMAScript 5
Rest Parameters
Increased Capabilities of the Function Constructor
The Spread Operator
The name Property
Choosing Appropriate Names
Special Cases of the name Property
Clarifying the Dual Purpose of Functions
Determining How a Function Was Called in ECMAScript 5
The new.target Metaproperty
Block-Level Functions
Deciding When to Use Block-Level Functions
Block-Level Functions in Non-Strict Mode
Arrow Functions
Arrow Function Syntax
Creating Immediately Invoked Function Expressions
No this Binding
Arrow Functions and Arrays
No arguments Binding
Identifying Arrow Functions
Tail Call Optimization
How Tail Calls Are Different in ECMAScript 6
How to Harness Tail Call Optimization
Summary
Chapter 4: Expanded Object Functionality
Object Categories
Object Literal Syntax Extensions
Property Initializer Shorthand
Concise Methods
Computed Property Names
New Methods
The Object.is() Method
The Object.assign() Method
Duplicate Object Literal Properties
Own Property Enumeration Order
Enhancements for Prototypes
Changing an Object’s Prototype
Easy Prototype Access with Super References
A Formal Method Definition
Summary
Chapter 5: Destructuring for Easier Data Access
Why Is Destructuring Useful?
Object Destructuring
Destructuring Assignment
Default Values
Assigning to Different Local Variable Names
Nested Object Destructuring
Array Destructuring
Destructuring Assignment
Default Values
Nested Array Destructuring
Rest Items
Mixed Destructuring
Destructured Parameters
Destructured Parameters Are Required
Default Values for Destructured Parameters
Summary
Chapter 6: Symbols and Symbol Properties
Creating Symbols
Using Symbols
Sharing Symbols
Symbol Coercion
Retrieving Symbol Properties
Exposing Internal Operations with Well-Known Symbols
The Symbol.hasInstance Method
The Symbol.isConcatSpreadable Property
The Symbol.match, Symbol.replace, Symbol.search, and Symbol.split Properties
The Symbol.toPrimitive Method
The Symbol.toStringTag Property
The Symbol.unscopables Property
Summary
Chapter 7: Sets and Maps
Sets and Maps in ECMAScript 5
Problems with Workarounds
Sets in ECMAScript 6
Creating Sets and Adding Items
Removing Items
The forEach() Method for Sets
Converting a Set to an Array
Weak Sets
Maps in ECMAScript 6
Map Methods
Map Initialization
The forEach() Method for Maps
Weak Maps
Summary
Chapter 8: Iterators and Generators
The Loop Problem
What Are Iterators?
What Are Generators?
Generator Function Expressions
Generator Object Methods
Iterables and for-of Loops
Accessing the Default Iterator
Creating Iterables
Built-In Iterators
Collection Iterators
String Iterators
NodeList Iterators
The Spread Operator and Nonarray Iterables
Advanced Iterator Functionality
Passing Arguments to Iterators
Throwing Errors in Iterators
Generator Return Statements
Delegating Generators
Asynchronous Task Running
A Simple Task Runner
Task Running with Data
An Asynchronous Task Runner
Summary
Chapter 9: Introducing JavaScript Classes
Class-Like Structures in ECMAScript 5
Class Declarations
A Basic Class Declaration
Why Use the Class Syntax?
Class Expressions
A Basic Class Expression
Named Class Expressions
Classes as First-Class Citizens
Accessor Properties
Computed Member Names
Generator Methods
Static Members
Inheritance with Derived Classes
Shadowing Class Methods
Inherited Static Members
Derived Classes from Expressions
Inheriting from Built-Ins
The Symbol.species Property
Using new.target in Class Constructors
Summary
Chapter 10: Improved Array Capabilities
Creating Arrays
The Array.of() Method
The Array.from() Method
New Methods on All Arrays
The find() and findIndex() Methods
The fill() Method
The copyWithin() Method
Typed Arrays
Numeric Data Types
Array Buffers
Manipulating Array Buffers with Views
Similarities Between Typed and Regular Arrays
Common Methods
The Same Iterators
The of() and from() Methods
Differences Between Typed and Regular Arrays
Behavioral Differences
Missing Methods
Additional Methods
Summary
Chapter 11: Promises and Asynchronous Programming
Asynchronous Programming Background
The Event Model
The Callback Pattern
Promise Basics
The Promise Life Cycle
Creating Unsettled Promises
Creating Settled Promises
Executor Errors
Global Promise Rejection Handling
Node.js Rejection Handling
Browser Rejection Handling
Chaining Promises
Catching Errors
Returning Values in Promise Chains
Returning Promises in Promise Chains
Responding to Multiple Promises
The Promise.all() Method
The Promise.race() Method
Inheriting from Promises
Promise-Based Asynchronous Task Running
Summary
Chapter 12: Proxies and the Reflection API
The Array Problem
Introducing Proxies and Reflection
Creating a Simple Proxy
Validating Properties Using the set Trap
Object Shape Validation Using the get Trap
Hiding Property Existence Using the has Trap
Preventing Property Deletion with the deleteProperty Trap
Prototype Proxy Traps
How Prototype Proxy Traps Work
Why Two Sets of Methods?
Object Extensibility Traps
Two Basic Examples
Duplicate Extensibility Methods
Property Descriptor Traps
Blocking Object.defineProperty()
Descriptor Object Restrictions
Duplicate Descriptor Methods
The ownKeys Trap
Function Proxies with the apply and construct Traps
Validating Function Parameters
Calling Constructors Without new
Overriding Abstract Base Class Constructors
Callable Class Constructors
Revocable Proxies
Solving the Array Problem
Detecting Array Indexes
Increasing length When Adding New Elements
Deleting Elements When Reducing length
Implementing the MyArray Class
Using a Proxy as a Prototype
Using the get Trap on a Prototype
Using the set Trap on a Prototype
Using the has Trap on a Prototype
Proxies as Prototypes on Classes
Summary
Chapter 13: Encapsulating Code with Modules
What Are Modules?
Basic Exporting
Basic Importing
Importing a Single Binding
Importing Multiple Bindings
Importing an Entire Module
A Subtle Quirk of Imported Bindings
Renaming Exports and Imports
Default Values in Modules
Exporting Default Values
Importing Default Values
Re-exporting a Binding
Importing Without Bindings
Loading Modules
Using Modules in Web Browsers
Browser Module Specifier Resolution
Summary
Appendix A: Minor Changes in ECMAScript 6
Working with Integers
Identifying Integers
Safe Integers
New Math Methods
Unicode Identifiers
Formalizing the __proto__ Property
Appendix B: Understanding ECMAScript 7 (2016)
The Exponentiation Operator
Order of Operations
Operand Restriction
The Array.prototype.includes() Method
How to Use Array.prototype.includes()
Value Comparison
A Change to Function-Scoped Strict Mode
Index
Updates
Level Up Your JavaScript
i
ii
iii
iv
v
vi
vii
viii
ix
x
xi
xii
xiii
xiv
xv
xvi
xvii
xviii
xix
xx
xxi
xxii
xxiii
xxiv
xxv
xxvi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327