CONTENTS IN DETAIL

FOREWORD by Dan Abramov

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

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

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

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

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

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

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

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

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

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

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

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

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

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

A
MINOR CHANGES IN ECMASCRIPT 6

Working with Integers

Identifying Integers

Safe Integers

New Math Methods

Unicode Identifiers

Formalizing the __proto__ Property

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