Exploring ES6: Upgrade to the next version of JavaScript

Купить бумажную книгу и читать

Купить бумажную книгу

По кнопке выше можно купить бумажные варианты этой книги и похожих книг на сайте интернет-магазина "Лабиринт".

Using the button above you can buy paper versions of this book and similar books on the website of the "Labyrinth" online store.

Реклама. ООО "ЛАБИРИНТ.РУ", ИНН: 7728644571, erid: LatgCADz8.

Название: Exploring ES6: Upgrade to the next version of javascript

Автор: Axel Rauschmayer

Издательство: Lean Publishing

Год: 2015

Страниц:555

Язык: English

Формат: pdf

Размер: 4 Mb

You are reading a book about ECMAScript 6 (ES6), a new version of javascript. It’s great that we can finally use that version, which had a long and eventful past: It was first conceived as ECMAScript 4, a successor to ECMAScript 3 (whose release was in December 1999). In July 2008, plans changed and the next versions of javascript were to be first a small incremental release (which became ES5) and then a larger, more powerful release. The latter had the code name Harmony and part of it became ES6.

About the book

Exploring ES6 …

Contains reliable and in-depth information on ECMAScript 6, the next version of javascript.

Is a book for people who already know javascript.

If you are a programmer and want to learn javascript (up to and including ECMAScript 5), check out Axel’s book “Speaking javascript” .

(Even though the official name is now ECMAScript 2015, I’ll keep calling it ECMAScript 6 – for now – because that’s how everybody knows this version.)

 

What you need to know about this book

Audience: javascript programmers

Why should I read this book?

How to read this book

Glossary and conventions

Documenting classes

Capitalization

Demo code on GitHub

Sidebars

Footnotes

Preface

Acknowledgements

I Background

1. About ECMAScript 6 (ES6)

1.1 TC39 (Ecma Technical Committee 39)

1.2 How ECMAScript 6 was designed

1.2.1 The design process after ES6

1.3 javascript versus ECMAScript

1.4 Upgrading to ES6

1.5 Goals for ES6

1.5.1 Goal: Be a better language

1.5.2 Goal: Improve interoperation

1.5.3 Goal: Versioning

1.6 An overview of ES6 features

1.7 A brief history of ECMAScript

1.7.1 The early years: ECMAScript 1–3

1.7.2 ECMAScript 4 (abandoned in July 2008)

1.7.3 ECMAScript Harmony

2. FAQ: ECMAScript 6

2.1 Isn’t ECMAScript 6 now called ECMAScript 2015?

2.2 How much of ES6 is supported natively by current engines?

2.3 How do I migrate my ECMAScript 5 code to ECMAScript 6?

2.4 Does it still make sense to learn ECMAScript 5?

2.5 Is ES6 bloated?

2.6 Isn’t the ES6 specification very big?

2.7 Does ES6 have array comprehensions?

2.8 Is ES6 statically typed?

2.9 Should I avoid classes?

2.10 Does ES6 have traits or mixins?

2.11 Why are there “fat” arrow functions (=>) in ES6, but no “thin” arrow functions (->)?

2.12 Where can I find more ES6 resources?

3. One javascript: avoiding versioning in ECMAScript 6

3.1 Versioning

3.1.1 Evolution without versioning

3.2 Strict mode and ECMAScript 6

3.2.1 Supporting sloppy (non-strict) mode

3.2.2 let declarations in sloppy mode

3.2.3 Block-level function declarations in sloppy mode

3.2.4 Other keywords

3.2.5 Implicit strict mode

3.2.6 Things that can’t be fixed

3.3 Conclusion

3.4 Further reading

4. First steps with ECMAScript 6

4.1 Trying out ECMAScript 6

4.1.1 The Babel REPL

4.1.2 babel-node

4.2 From var to let/const

4.3 From IIFEs to blocks

4.4 From concatenating strings to template literals

4.4.1 String interpolation

4.4.2 Multi-line strings

4.5 From function expressions to arrow functions

4.6 Handling multiple return values

4.6.1 Multiple return values via arrays

4.6.2 Multiple return values via objects

4.7 From for to forEach() to for-of

4.8 Handling parameter default values

4.9 Handling named parameters

4.9.1 Making the parameter optional

4.10 From arguments to rest parameters

4.11 From apply() to the spread operator (...)

4.11.1 Math.max()

4.11.2 Array.prototype.push()

4.12 From concat() to the spread operator (...)

4.13 From constructors to classes

4.13.1 Base classes

4.13.2 Derived classes

4.14 From custom error constructors to subclasses of Error

4.15 From function expressions in object literals to method definitions

4.16 From objects to Maps

4.17 From CommonJS modules to ES6 modules

4.17.1 Multiple exports

4.17.2 Single exports

4.18 What to do next

5. Deploying ECMAScript 6

5.1 Using ECMAScript 6 today

5.1.1 Using ECMAScript 6 natively

5.2 Transpilation tools

5.2.1 Choosing a transpiler

5.2.2 Choosing a package manager

5.2.3 Choosing a module system

5.3 Other useful ES6 tools and libraries

5.4 ES6 REPLs

5.5 Are there ES6 features that can’t be transpiled to ES5?

5.5.1 Better syntax for existing features

5.5.2 New functionality in the standard library

5.5.3 Completely new features

5.6 Example transpilation setups

5.7 Example setup: Client-side ES6 via webpack and Babel

5.7.1 webpack features

5.7.2 Installing webpack

5.7.3 Using webpack and ES6 in a project

5.8 Example setup: Dynamically transpiled ES6 on Node.js via Babel

5.8.1 Running normal Node.js code via Babel

5.8.2 Running Jasmine unit tests via Babel

5.9 Example setup: Statically transpiled ES6 on Node.js via Babel and gulp

5.9.1 Installation

5.9.2 Source maps

5.9.3 The gulp file

5.9.4 Transpilation

5.9.5 Running the transpiled code

II Data

6. New number and Math features

6.1 Overview

6.2 New integer literals

6.2.1 Use case for octal literals: Unix-style file permissions

6.2.2 parseInt() and the new integer literals

6.3 New static Number properties

6.3.1 Previously global functions

6.3.2 Number.EPSILON

6.3.3 Number.isInteger(number)

6.3.4 Safe Integers

6.4 Math

6.4.1 Various numerical functionality

6.4.2 Using 0 instead of 1 with exponentiation and logarithm

6.4.3 Logarithms to base 2 and 10

6.4.4 Support for compiling to javascript

6.4.5 Bitwise operations

6.4.6 Trigonometric methods

6.5 FAQ: numbers

6.5.1 How can I use integers beyond javascript’s 53 bit range?

7. New string features

7.1 Overview

7.2 Unicode code point escapes

7.3 String interpolation, multi-line string literals and raw string literals

7.4 Iterating over strings

7.4.1 Iteration honors Unicode code points

7.4.2 Counting code points

7.4.3 Reversing strings with non-BMP code points

7.5 Numeric values of code points

7.6 Checking for containment and repeating strings

7.7 All new string methods

8. Symbols

8.1 Overview

8.1.1 Use case 1: unique property keys

8.1.2 Use case 2: constants representing concepts

8.2 A new primitive type

8.2.1 Symbols as property keys

8.2.2 Enumerating own property keys

8.3 Using symbols to represent concepts

8.4 Symbols as keys of properties

8.4.1 Symbols as keys of internal properties

8.4.2 Symbols as keys of meta-level properties

8.5 Crossing realms with symbols

8.6 Wrapper objects for symbols

8.6.1 Property access via [ ]

8.7 Converting symbols to other primitive types

8.7.1 Pitfall: coercion to string

8.7.2 Making sense of the coercion rules

8.7.3 Explicit and implicit conversion in the spec

8.8 JSON and symbols

8.8.1 Generating JSON via JSON.stringify()

8.8.2 Parsing JSON via JSON.parse()

8.9 FAQ: symbols

8.9.1 Can I use symbols to define private properties?

8.9.2 Are symbols primitives or objects?

8.9.3 Do we really need symbols? Aren’t strings enough?

8.9.4 Are javascript’s symbols like Ruby’s symbols?

8.10 The symbol API

8.10.1 The function Symbol

8.10.2 Well-known symbols

8.10.3 Global symbol registry

9. Template literals and tagged templates

9.1 Overview

9.2 Introduction

9.2.1 Template literals

9.2.2 Tagged templates

9.3 Examples of using tagged templates

9.3.1 Raw strings

9.3.2 Escaping parts of a regular expression

9.3.3 Tagged templates for more powerful regular expressions

9.3.4 Query languages

9.3.5 React JSX via tagged templates

9.3.6 Text localization (L10N)

9.4 Implementing tag functions

9.4.1 Escaping in tagged templates: cooked vs. raw

9.4.2 Example: implementing a tag function for HTML templating

9.4.3 Example: quoting parts of regular expressions

9.5 FAQ: template literals and tagged templates

9.5.1 Where do template literals and tagged literals come from?

9.5.2 What is the difference between macros and tagged templates?

9.5.3 Can I load a template literal from an external source?

9.5.4 Why are backticks the delimiters for template literals and tagged templates?

9.5.5 Weren’t template literals once called template strings?

10. Variables and scoping

10.1 Overview

10.1.1 let

10.1.2 const

10.1.3 Ways of declaring variables

10.2 Block scoping via let and const

10.3 const creates immutable variables

10.3.1 Pitfall: const does not make the value immutable

10.3.2 const in loop bodies

10.4 The temporal dead zone

10.4.1 typeof and the temporal dead zone

10.5 let and const in loop heads

10.5.1 for loop

10.5.2 for-of loop and for-in loop

10.6 Parameters

10.6.1 Parameters versus local variables

10.6.2 Parameter default values and the temporal dead zone

10.6.3 Parameter default values don’t see the scope of the body

10.7 The global object

10.8 Function declarations and class declarations

10.9 Coding style: var vs. let vs. const

11. Destructuring

11.1 Overview

11.2 Background: Constructing data (object and Array literals) vs. extracting data (destructuring)

11.3 Patterns

11.3.1 Pick what you need

11.4 How do patterns access the innards of values?

11.4.1 Object patterns coerce values to objects

11.4.2 Array patterns work with iterables

11.5 If a part has no match

11.5.1 Default values

11.6 More object destructuring features

11.6.1 Property value shorthands

11.6.2 Computed property keys

11.7 More Array destructuring features

11.7.1 Elision

11.7.2 Rest operator (...)

11.8 You can assign to more than just variables

11.9 Pitfalls of destructuring

11.9.1 Don’t start a statement with a curly brace

11.9.2 You can’t mix declaring and assigning to existing variables

11.10 Examples of destructuring

11.10.1 Destructuring return values

11.10.2 Multiple return values

11.11 The destructuring algorithm

11.11.1 The algorithm

11.11.2 Applying the algorithm

11.11.3 Conclusion

12. Parameter handling

12.1 Overview

12.1.1 Spread operator (...)

12.2 Parameter handling as destructuring

12.3 Parameter default values

12.3.1 Why does undefined trigger default values?

12.3.2 Referring to other parameters in default values

12.3.3 Referring to “inner” variables in default values

12.4 Rest parameters

12.4.1 No more arguments!

12.5 Simulating named parameters

12.5.1 Named Parameters as Descriptions

12.5.2 Optional Named Parameters

12.5.3 Simulating Named Parameters in javascript

12.6 Examples of destructuring in parameter handling

12.6.1 Reminder: parentheses around single parameters of arrow functions

12.6.2 forEach() and destructuring

12.6.3 Transforming Maps

12.6.4 Handling an Array returned via a Promise

12.7 Coding style tips

12.7.1 Optional parameters

12.7.2 Required parameters

12.7.3 Enforcing a maximum arity

12.8 The spread operator (...)

12.8.1 Spreading into function and method calls

12.8.2 Spreading into constructors

12.8.3 Spreading into Arrays

III Modularity

13. Callable entities in ECMAScript 6

13.1 Callable entities in ES6

13.1.1 Ways of calling in ES6

13.1.2 Traditional functions

13.1.3 Generator functions

13.1.4 Method definitions

13.1.5 Generator method definitions

13.1.6 Arrow functions

13.1.7 Classes

13.2 Thoughts on style

13.2.1 Prefer arrow functions as callbacks

13.2.2 Be careful with function declarations

13.2.3 Prefer method definitions for methods

13.2.4 Methods versus callbacks

13.2.5 Avoid IIFEs in ES6

13.2.6 Use classes

13.3 Dispatched and direct method calls in ECMAScript 5 and 6

13.3.1 Background: prototype chains

13.3.2 Dispatched method calls

13.3.3 Direct method calls

13.3.4 Use cases for direct method calls

13.3.5 Abbreviations for Object.prototype and Array.prototype

14. Arrow functions

14.1 Overview

14.2 Traditional functions are bad non-method functions, due to this

14.2.1 Solution 1: that = this

14.2.2 Solution 2: specifying a value for this

14.2.3 Solution 3: bind(this)

14.2.4 ECMAScript 6 solution: arrow functions

14.3 Arrow function syntax

14.4 Lexical variables

14.4.1 Sources of variable values: static versus dynamic

14.4.2 Variables that are lexical in arrow functions

14.5 Syntax pitfalls

14.5.1 Arrow functions bind very loosely

14.5.2 Immediately-invoked arrow functions

14.5.3 Omitting parentheses around single parameters

14.5.4 You can’t use statements as expression bodies

14.5.5 Returning an object literal

14.6 Arrow functions versus normal functions

15. New OOP features besides classes

15.1 Overview

15.1.1 New object literal features

15.1.2 New methods in Object

15.2 New features of object literals

15.2.1 Method definitions

15.2.2 Property value shorthands

15.2.3 Computed property keys

15.3 New methods of Object

15.3.1 Object.assign(target, source_1, source_2, ···)

15.3.2 Object.getOwnPropertySymbols(obj)

15.3.3 Object.is(value1, value2)

15.3.4 Object.setPrototypeOf(obj, proto)

15.4 Iterating over property keys in ES6

15.4.1 Iteration order of property keys

15.5 FAQ: object literals

15.5.1 Can I use super in object literals?

16. Classes

16.1 Overview

16.2 The essentials

16.2.1 Base classes

16.2.2 Inside the body of a class definition

16.2.3 Subclassing

16.3 The details of classes

16.3.1 Various checks

16.3.2 Attributes of properties

16.4 The details of subclassing

16.4.1 Prototype chains

16.4.2 Allocating and initializing instances

16.4.3 Why can’t you subclass built-in constructors in ES5?

16.4.4 Referring to super-properties in methods

16.5 Constructor calls explained via javascript code

16.5.1 Internal variables and properties

16.5.2 Environments

16.5.3 Constructor calls

16.5.4 Super-constructor calls

16.6 The species pattern

16.6.1 The standard species pattern

16.6.2 The species pattern for Arrays

16.6.3 The species pattern in static methods

16.6.4 Overriding the default species in subclasses

16.7 FAQ: classes

16.7.1 Why can’t classes be function-called?

16.7.2 How do instantiate a class, given an Array of arguments?

16.7.3 How do I manage private data for classes?

16.7.4 What is next for classes?

16.8 The pros and cons of classes

16.8.1 Complaint: ES6 classes obscure the true nature of javascript inheritance

16.8.2 Complaint: Classes provide only single inheritance

16.8.3 Complaint: Classes lock you in, due to mandatory new

16.9 Further reading

17. Modules

17.1 Overview

17.1.1 Multiple named exports

17.1.2 Single default export

17.1.3 Browsers: scripts versus modules

17.2 Modules in javascript

17.2.1 ECMAScript 5 module systems

17.2.2 ECMAScript 6 modules

17.3 The basics of ES6 modules

17.3.1 Named exports (several per module)

17.3.2 Default exports (one per module)

17.3.3 Imports are hoisted

17.3.4 Imports are read-only views on exports

17.3.5 Support for cyclic dependencies

17.3.6 Module files are normal javascript files

17.3.7 Be careful with ES6 transpilers

17.4 Importing and exporting in detail

17.4.1 Importing styles

17.4.2 Exporting styles: inline versus clause

17.4.3 Re-exporting

17.4.4 All exporting styles

17.4.5 Having both named exports and a default export in a module

17.5 The ECMAScript 6 module loader API

17.5.1 Loaders

17.5.2 Loader method: importing modules

17.5.3 More loader methods

17.5.4 Configuring module loading

17.6 Using ES6 modules in browsers

17.6.1 Browsers: asynchronous modules versus synchronous scripts

17.6.2 Bundling

17.7 Details: imports as views on exports

17.7.1 In CommonJS, imports are copies of exported values

17.7.2 In ES6, imports are live read-only views on exported values

17.7.3 Implementing views

17.7.4 Imports as views in the spec

17.8 Design goals for ES6 modules

17.8.1 Default exports are favored

17.8.2 Static module structure

17.8.3 Support for both synchronous and asynchronous loading

17.8.4 Support for cyclic dependencies between modules

17.9 FAQ: modules

17.9.1 Can I use a variable to specify from which module I want to import?

17.9.2 Can I import a module conditionally or on demand?

17.9.3 Can I use destructuring in an import statement?

17.9.4 Are named exports necessary? Why not default-export objects?

17.9.5 Can I eval() modules?

17.10 Benefits of ECMAScript 6 modules

17.11 Further reading

IV Collections

18. New Array features

18.1 Overview

18.2 New static Array methods

18.2.1 Array.from(arrayLike, mapFunc?, thisArg?)

18.2.2 Array.of(...items)

18.3 New Array.prototype methods

18.3.1 Iterating over Arrays

18.3.2 Searching for Array elements

18.3.3 Array.prototype.copyWithin()

18.3.4 Array.prototype.fill()

19. Maps and Sets

19.1 Overview

19.1.1 Maps

19.1.2 Sets

19.1.3 WeakMaps

19.2 Map

19.2.1 Basic operations

19.2.2 Setting up a Map

19.2.3 Keys

19.2.4 Iterating

19.2.5 Looping over entries

19.2.6 Mapping and filtering Maps

19.2.7 Combining Maps

19.2.8 Map API

19.3 WeakMap

19.3.1 Using WeakMaps for private data

19.3.2 WeakMap API

19.4 Set

19.4.1 Basic operations

19.4.2 Setting up a Set

19.4.3 Comparing Set elements

19.4.4 Iterating

19.4.5 Mapping and filtering

19.4.6 Union, intersection, difference

19.4.7 Set API

19.5 WeakSet

19.5.1 WeakSet API

19.6 FAQ: Maps and Sets

19.6.1 Why do Maps and Sets have the property size and not length?

19.6.2 Why can’t I configure how Maps and Sets compare keys and values?

19.6.3 Is there a way to specify a default value when getting something out of a Map?

19.6.4 When should I use a Map, when an object?

20. Typed Arrays

20.1 Overview

20.2 Introduction

20.2.1 Element types

20.2.2 Handling overflow and underflow

20.2.3 Endianness

20.2.4 Negative indices

20.3 ArrayBuffers

20.3.1 ArrayBuffer constructor

20.3.2 Static ArrayBuffer methods

20.3.3 ArrayBuffer.prototype properties

20.4 Typed Arrays

20.4.1 Typed Arrays versus normal Arrays

20.4.2 Typed Arrays are iterable

20.4.3 Converting Typed Arrays to and from normal Arrays

20.4.4 The Species pattern for Typed Arrays

20.4.5 The inheritance hierarchy of Typed Arrays

20.4.6 Static TypedArray methods

20.4.7 TypedArray.prototype properties

20.4.8 «ElementType»Array constructor

20.4.9 Static «ElementType»Array properties

20.4.10 «ElementType»Array.prototype properties

20.4.11 Concatenating Typed Arrays

20.5 DataViews

20.5.1 DataView constructor

20.5.2 DataView.prototype properties

20.6 Browser APIs that support Typed Arrays

20.6.1 File API

20.6.2 XMLHttpRequest

20.6.3 Fetch API

20.6.4 Canvas

20.6.5 WebSockets

20.6.6 Other APIs

20.7 Extended example: JPEG SOF0 decoder

20.7.1 The JPEG file format

20.7.2 The javascript code

20.8 Availability

21. Iterables and iterators

21.1 Overview

21.2 Iterability

21.3 Iterable data sources

21.3.1 Arrays

21.3.2 Strings

21.3.3 Maps

21.3.4 Sets

21.3.5 arguments

21.3.6 DOM data structures

21.3.7 Iterable computed data

21.3.8 Plain objects are not iterable

21.4 Iterating language constructs

21.4.1 Destructuring via an Array pattern

21.4.2 The for-of loop

21.4.3 Array.from()

21.4.4 The spread operator (...)

21.4.5 Maps and Sets

21.4.6 Promises

21.4.7 yield*

21.5 Implementing iterables

21.5.1 Iterators that are iterable

21.5.2 Optional iterator methods: return() and throw()

21.6 More examples of iterables

21.6.1 Tool functions that return iterables

21.6.2 Combinators for iterables

21.6.3 Infinite iterables

21.7 FAQ: iterables and iterators

21.7.1 Isn’t the iteration protocol slow?

21.7.2 Can I reuse the same object several times?

21.7.3 Why doesn’t ECMAScript 6 have iterable combinators?

21.7.4 Aren’t iterables difficult to implement?

21.8 The ECMAScript 6 iteration protocol in depth

21.8.1 Iteration

21.8.2 Closing iterators

21.8.3 Checklist

22. Generators

22.1 Overview

22.1.1 Implementing iterables via generators

22.1.2 Blocking on asynchronous function calls

22.2 What are generators?

22.2.1 Ways of creating generators

22.2.2 Roles played by generators

22.3 Generators as iterators (data production)

22.3.1 Ways of iterating over a generator

22.3.2 Returning from a generator

22.3.3 Example: iterating over properties

22.3.4 You can only yield in generators

22.3.5 Recursion via yield* (for output)

22.4 Generators as observers (data consumption)

22.4.1 Sending values via next()

22.4.2 yield binds loosely

22.4.3 return() and throw()

22.4.4 return() terminates the generator

22.4.5 throw() signals an error

22.4.6 Example: processing asynchronously pushed data

22.4.7 yield*: the full story

22.5 Generators as coroutines (cooperative multitasking)

22.5.1 The full generator interface

22.5.2 Cooperative multitasking

22.5.3 The limitations of cooperative multitasking via generators

22.6 Examples of generators

22.6.1 Implementing iterables via generators

22.6.2 Generators for lazy evaluation

22.6.3 Cooperative multi-tasking via generators

22.7 Inheritance within the iteration API (including generators)

22.7.1 IteratorPrototype

22.7.2 The value of this in generators

22.8 Style consideration: whitespace before and after the asterisk

22.8.1 Generator function declarations and expressions

22.8.2 Generator method definitions

22.8.3 Formatting recursive yield

22.8.4 Documenting generator functions and methods

22.9 Conclusion

22.10 Further reading

V Standard library

23. New regular expression features

23.1 Overview

23.2 New flag /y (sticky)

23.2.1 RegExp.prototype.exec(str)

23.2.2 RegExp.prototype.test(str)

23.2.3 String.prototype.search(regex)

23.2.4 String.prototype.match(regex)

23.2.5 String.prototype.split(separator, limit)

23.2.6 String.prototype.replace(search, replacement)

23.2.7 Example: using sticky matching for tokenizing

23.2.8 Example: manually implementing sticky matching

23.3 New flag /u (unicode)

23.3.1 Consequence: lone surrogates in the regular expression only match lone surrogates

23.3.2 Consequence: you can put code points in character classes

23.3.3 Consequence: the dot operator (.) matches code points, not code units

23.3.4 Consequence: quantifiers apply to code points, not code units

23.4 New data property flags

23.5 RegExp() can be used as a copy constructor

23.6 String methods using regular expressions delegate to regular expression methods

24. Asynchronous programming (background)

24.1 The javascript call stack

24.2 The browser event loop

24.2.1 Timers

24.2.2 Displaying DOM changes

24.2.3 Run-to-completion semantics

24.2.4 Blocking the event loop

24.2.5 Avoiding blocking

24.3 Receiving results asynchronously

24.3.1 Asynchronous results via events

24.3.2 Asynchronous results via callbacks

24.3.3 Continuation-passing style

24.3.4 Composing code in CPS

24.3.5 Pros and cons of callbacks

24.4 Looking ahead

24.5 Further reading

25. Promises for asynchronous programming

25.1 Overview

25.1.1 Handling Arrays of Promises

25.2 Promises

25.3 A first example

25.4 Creating and using Promises

25.4.1 Producing a Promise

25.4.2 Consuming a Promise

25.4.3 Only handling fulfillments or rejections

25.5 Examples

25.5.1 Example: promisifying fs.readFile()

25.5.2 Example: promisifying XMLHttpRequest

25.5.3 Example: delaying an activity

25.5.4 Example: timing out a Promise

25.6 Chaining Promises

25.6.1 Resolving Q with normal values

25.6.2 Resolving Q with thenables

25.6.3 Resolving Q from onRejected

25.6.4 Rejecting Q by throwing exceptions

25.6.5 Exceptions in executors

25.6.6 Chaining errors

25.7 Composition

25.7.1 map() via Promise.all()

25.7.2 Timing out via Promise.race()

25.8 Promises are always async

25.9 Cheat sheet: the ECMAScript 6 Promise API

25.9.1 Glossary: Promises

25.9.2 Promise constructor

25.9.3 Static Promise methods

25.9.4 Promise.prototype methods

25.10 Pros and cons of Promises

25.10.1 The pros

25.10.2 The cons

25.11 Promises and generators

25.12 Debugging Promises

25.13 The internals of Promises

25.13.1 A stand-alone Promise

25.13.2 Chaining

25.13.3 Flattening

25.13.4 Promise states in more detail

25.13.5 Exceptions

25.13.6 Revealing constructor pattern

25.14 Two useful additional Promise methods

25.14.1 done()

25.14.2 finally()

25.15 ES6-compatible Promise libraries

25.16 Interfacing with legacy asynchronous code

25.16.1 Interfacing with Node.js

25.16.2 Interfacing with jQuery

25.17 Further reading

VI Miscellaneous

26. Unicode in ES6

26.1 Unicode is better supported in ES6

26.2 Escape sequences in ES6

26.2.1 Where can escape sequences be used?

26.2.2 Escape sequences in the ES6 spec

27. Tail call optimization

27.1 What is tail call optimization?

27.1.1 Normal execution

27.1.2 Tail call optimization

27.2 Checking whether a function call is in a tail position

27.2.1 Tail calls in expressions

27.2.2 Tail calls in statements

27.2.3 Tail call optimization can only be made in strict mode

27.2.4 Pitfall: solo function calls are never in tail position

27.3 Tail-recursive functions

27.3.1 Tail-recursive loops

28. Meta programming with proxies

28.1 Overview

28.2 Programming versus meta programming

28.2.1 Kinds of meta programming

28.3 A first look at proxies

28.3.1 Function-specific traps

28.3.2 Revocable proxies

28.3.3 Proxies as prototypes

28.3.4 Forwarding intercepted operations

28.4 Use cases for proxies

28.4.1 Implementing the DOM in javascript

28.4.2 Accessing a restful web service

28.4.3 Tracing property accesses

28.4.4 Warning about unknown properties

28.4.5 Negative Array indices

28.4.6 Data binding

28.4.7 Revocable references

28.4.8 Other use cases

28.5 The design of the proxy API

28.5.1 Stratification: keeping base level and meta level separate

28.5.2 Virtual objects versus wrappers

28.5.3 Transparent virtualization and handler encapsulation

28.5.4 The meta object protocol and proxy traps

28.5.5 Enforcing invariants for proxies

28.6 Reference: the proxy API

28.6.1 Creating proxies

28.6.2 Handler methods

28.6.3 Invariants of handler methods

28.6.4 Operations that affect the prototype chain

28.6.5 Reflect

28.7 Conclusion

28.8 Further reading

29. Coding style tips for ECMAScript 6

Дата создания страницы: