What you need to know about this book
- Audience: JavaScript programmers
- Why should I read this book?
- How to read this book
- Sources of this book
- Glossary
- Conventions
- Demo code on GitHub
- Sidebars
- Tips for reading
- Code on GitHub
- Information
- Question
- Warning
- External material
- Related parts of the spec
- Footnotes
Foreword
Preface
Acknowledgements
About the author
- IBackground
1.About ECMAScript 6 (ES6)
- 1.1TC39 (Ecma Technical Committee 39)
- 1.2How ECMAScript 6 was designed
- 1.3JavaScript versus ECMAScript
- 1.4Upgrading to ES6
- 1.5Goals for ES6
- 1.6Categories of ES6 features
- 1.7A brief history of ECMAScript
- Sources of this section:
2.FAQ: ECMAScript 6
- 2.1How can I use ES6 today?
- 2.2Isn’t ECMAScript 6 now called ECMAScript 2015?
- 2.3How do I migrate my ECMAScript 5 code to ECMAScript 6?
- 2.4Does it still make sense to learn ECMAScript 5?
- 2.5Is ES6 bloated?
- 2.6Isn’t the ES6 specification very big?
- 2.7Does ES6 have array comprehensions?
- 2.8Is ES6 statically typed?
3.One JavaScript: avoiding versioning in ECMAScript 6
- 3.1Versioning
- 3.2Strict mode and ECMAScript 6
- 3.3Breaking changes in ES6
- 3.4Conclusion
- 3.5Further reading
4.Core ES6 features
- 4.1From
vartoconst/let - 4.2From IIFEs to blocks
- 4.3From concatenating strings to template literals
- 4.4From function expressions to arrow functions
- 4.5Handling multiple return values
- 4.6From
fortoforEach()tofor-of - 4.7Handling parameter default values
- 4.8Handling named parameters
- 4.9From
argumentsto rest parameters - 4.10From
apply()to the spread operator (...) - 4.11From
concat()to the spread operator (...) - 4.12From function expressions in object literals to method definitions
- 4.13From constructors to classes
- 4.14From custom error constructors to subclasses of
Error - 4.15From objects to Maps
- 4.16New string methods
- 4.17New Array methods
- 4.18From CommonJS modules to ES6 modules
- 4.19What to do next
- IIData
5.New number and Math features
- 5.1Overview
- 5.2New integer literals
- 5.3New static
Numberproperties - Source of this section
- 5.4New
Mathfunctionality - 5.5FAQ: numbers
6.New string features
- 6.1Overview
- 6.2Unicode code point escapes
- 6.3String interpolation, multi-line string literals and raw string literals
- 6.4Iterating over strings
- Remaining problem: combining marks
- 6.5Numeric values of code points
- 6.6Checking for inclusion
- 6.7Repeating strings
- 6.8String methods that delegate regular expression work to their parameters
- 6.9Reference: the new string methods
7.Symbols
- 7.1Overview
- 7.2A new primitive type
- 7.3Using symbols to represent concepts
- 7.4Symbols as keys of properties
- 7.5Converting symbols to other primitive types
- 7.6Wrapper objects for symbols
- 7.7Crossing realms with symbols
- 7.8FAQ: symbols
- 7.9The spelling of well-known symbols: why
Symbol.iteratorand notSymbol.ITERATOR(etc.)? - 7.10The symbol API
8.Template literals
- 8.1Overview
- 8.2Introduction
- Spec: line terminators in template literals
- 8.3Examples of using tagged template literals
- 8.4Implementing tag functions
- Tagged template literals in the spec
- Escaping in tagged template literals in the spec
- 8.5FAQ: template literals and tagged template literals
9.Variables and scoping
- 9.1Overview
- 9.2Block scoping via
letandconst - 9.3
constcreates immutable variables - Spec detail: changing a
constvariable always throws aTypeError - 9.4The temporal dead zone
- 9.5
letandconstin loop heads forloop: per-iteration bindings in the specfor-ofloop: per-iteration bindings in the spec- 9.6Parameters as variables
- 9.7The global object
- 9.8Function declarations and class declarations
- 9.9Coding style:
constversusletversusvar
10.Destructuring
- 10.1Overview
- 10.2Background: Constructing data versus extracting data
- 10.3Patterns for destructuring
- 10.4How do patterns access the innards of values?
- 10.5Default values
- Still confused?
- 10.6More object destructuring features
- 10.7More Array destructuring features
- 10.8You can assign to more than just variables
- 10.9Pitfalls of destructuring
- 10.10Examples of destructuring
- 10.11The destructuring algorithm
11.Parameter handling
- 11.1Overview
- 11.2Parameter handling as destructuring
- 11.3Parameter default values
- 11.4Rest parameters
- 11.5Simulating named parameters
- 11.6Examples of destructuring in parameter handling
- 11.7Coding style tips
- 11.8The spread operator (
...) - IIIModularity
12.Callable entities in ECMAScript 6
- 12.1Overview
- 12.2Ways of calling in ES6
- 12.3Recommendations for using callable entities
- 12.4ES6 callable entities in detail
- 12.5Dispatched and direct method calls in ES5 and ES6
- 12.6The
nameproperty of functions - 12.7FAQ: callable entities
13.Arrow functions
- 13.1Overview
- 13.2Traditional functions are bad non-method functions, due to
this - 13.3Arrow function syntax
- 13.4Lexical variables
- 13.5Syntax pitfalls
- 13.6Immediately-invoked arrow functions
- 13.7Arrow functions versus
bind() - 13.8Arrow functions versus normal functions
- 13.9FAQ: arrow functions
14.New OOP features besides classes
- 14.1Overview
- 14.2New features of object literals
- 14.3New methods of
Object - 14.4Traversing properties in ES6
- 14.5Assigning versus defining properties
- 14.6
__proto__in ECMAScript 6 - 14.7Enumerability in ECMAScript 6
- 14.8Customizing basic language operations via well-known symbols
- 14.9FAQ: object literals
15.Classes
- 15.1Overview
- 15.2The essentials
- 15.3Private data for classes
- 15.4Simple mixins
- 15.5The details of classes
- 15.6The details of subclassing
- Methods are a special kind of function now
- 15.7The species pattern
- 15.8The pros and cons of classes
- traits.js: traits library for JavaScript
- 15.9FAQ: classes
- 15.10What is next for classes?
- 15.11Further reading
16.Modules
- 16.1Overview
- 16.2Modules in JavaScript
- 16.3The basics of ES6 modules
- 16.4Importing and exporting in detail
- 16.5The ECMAScript 6 module loader API
- The module loader API is not part of the ES6 standard
- The module loader API is work in progress
- 16.6Using ES6 modules in browsers
- Support for ES6 modules in browsers is work in progress
- Sources of this section
- 16.7Details: imports as views on exports
- 16.8Design goals for ES6 modules
- 16.9FAQ: modules
- 16.10Advantages of ECMAScript 6 modules
- 16.11Further reading
- IVCollections
17.The for-of loop
- 17.1Overview
- 17.2Introducing the
for-ofloop - 17.3Pitfall:
for-ofonly works with iterable values - 17.4Iteration variables:
constdeclarations versusvardeclarations - 17.5Iterating with existing variables, object properties and Array elements
- 17.6Iterating with a destructuring pattern
18.New Array features
- 18.1Overview
- 18.2New static
Arraymethods - 18.3New
Array.prototypemethods - 18.4ES6 and holes in Arrays
- 18.5Configuring which objects are spread by
concat()(Symbol.isConcatSpreadable) Symbol.isConcatSpreadablein the ES6 spec- 18.6The numeric range of Array indices
- Enforcing the smaller range of normal Arrays
19.Maps and Sets
- 19.1Overview
- 19.2Map
- 19.3WeakMap
- 19.4Set
- 19.5WeakSet
- 19.6FAQ: Maps and Sets
20.Typed Arrays
- 20.1Overview
- 20.2Introduction
- 20.3ArrayBuffers
- 20.4Typed Arrays
- 20.5DataViews
- 20.6Browser APIs that support Typed Arrays
- 20.7Extended example: JPEG SOF0 decoder
- 20.8Availability
21.Iterables and iterators
- 21.1Overview
- 21.2Iterability
- 21.3Iterable data sources
- 21.4Iterating language constructs
- 21.5Implementing iterables
- 21.6More examples of iterables
- 21.7FAQ: iterables and iterators
- 21.8The ECMAScript 6 iteration protocol in depth
22.Generators
- 22.1Overview
- 22.2What are generators?
- 22.3Generators as iterators (data production)
- 22.4Generators as observers (data consumption)
- Further reading
- 22.5Generators as coroutines (cooperative multitasking)
- 22.6Examples of generators
- 22.7Inheritance within the iteration API (including generators)
- 22.8Style consideration: whitespace before and after the asterisk
- 22.9FAQ: generators
- 22.10Conclusion
- 22.11Further reading
- VStandard library
23.New regular expression features
- 23.1Overview
- 23.2New flag
/y(sticky) - 23.3New flag
/u(unicode) - 23.4New data property
flags - 23.5
RegExp()can be used as a copy constructor - 23.6String methods that delegate to regular expression methods
- Further reading
24.Asynchronous programming (background)
- 24.1The JavaScript call stack
- 24.2The browser event loop
- 24.3Receiving results asynchronously
- 24.4Looking ahead
- 24.5Further reading
25.Promises for asynchronous programming
- 25.1Overview
- 25.2Introduction: Promises
- 25.3A first example
- 25.4Three ways of understanding Promises
- 25.5Creating and using Promises
- 25.6Examples
- 25.7Other ways of creating Promises
- 25.8Chaining Promises
- 25.9Common Promise chaining mistakes
- 25.10Tips for error handling
- 25.11Composing Promises
- 25.12Two useful additional Promise methods
- 25.13Node.js: using callback-based sync functions with Promises
- 25.14ES6-compatible Promise libraries
- 25.15Next step: using Promises via generators
- 25.16Promises in depth: a simple implementation
- 25.17Advantages and limitations of Promises
- 25.18Reference: the ECMAScript 6 Promise API
- 25.19Further reading
- VIMiscellaneous
26.Unicode in ES6
- 26.1Unicode is better supported in ES6
- 26.2Escape sequences in ES6
- Further reading
27.Tail call optimization
- 27.1What is tail call optimization?
- 27.2Checking whether a function call is in a tail position
- 27.3Tail-recursive functions
28.Metaprogramming with proxies
- 28.1Overview
- 28.2Programming versus metaprogramming
- 28.3Proxies explained
- 28.4Use cases for proxies
- 28.5The design of the proxy API
- 28.6FAQ: proxies
- 28.7Reference: the proxy API
- 28.8Conclusion
- 28.9Further reading
29.Coding style tips for ECMAScript 6
30.An overview of what’s new in ES6
- 30.1Categories of ES6 features
- 30.2New number and
Mathfeatures - 30.3New string features
- 30.4Symbols
- 30.5Template literals
- 30.6Variables and scoping
- 30.7Destructuring
- 30.8Parameter handling
- 30.9Callable entities in ECMAScript 6
- 30.10Arrow functions
- 30.11New OOP features besides classes
- 30.12Classes
- 30.13Modules
- 30.14The
for-ofloop - 30.15New Array features
- 30.16Maps and Sets
- 30.17Typed Arrays
- 30.18Iterables and iterators
- 30.19Generators
- 30.20New regular expression features
- 30.21Promises for asynchronous programming
- 30.22Metaprogramming with proxies