The Joy of JavaScript [1 ed.] 1617295868, 9781617295867

Whether building interactive browser-based applications or creating server-side applications in Node, JavaScript is the

508 44 6MB

English Pages 360 [362] Year 2021

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
The Joy of JavaScript
brief contents
contents
preface
acknowledgments
about this book
Who should read this book
How this book is organized
Part 1: Objects
Part 2: Functions
Part 3: Code
Part 4: Data
About the code
Other online resources
about the author
about the cover illustration
1 JavaScript reloaded
1.1 Evolving JavaScript
1.2 Objects
1.3 Functions
1.4 Code
1.5 Data
1.6 Sample application: Blockchain
Summary
Part 1—Objects
2 Inheritance-based object modeling
2.1 Reviewing prototypal inheritance
2.1.1 Property resolution process
2.1.2 Differential inheritance
2.2 Constructor functions
2.2.1 Functions as templates
2.2.2 Sharing properties by using constructors and prototypes
2.3 Class-based inheritance
Summary
3 Linked, compositional object models
3.1 Types of object links
3.1.1 Implicit
3.1.2 Explicit
3.2 OLOO
3.3 Understanding Object.assign
3.3.1 Object.assign uncovered
3.3.2 Assignment vs definition
3.4 Assembling objects using mixin composition
3.4.1 Anatomy of a mixin
3.4.2 Multiple inheritance and linearization
3.4.3 Composing objects using Object.assign and the spread operator
3.5 Applying shared mixins to multiple objects
Summary
Part 2—Functions
4 Writing composable, pure code
4.1 What is functional programming?
4.1.1 Functions as data
4.1.2 The functional way
4.2 Functional versus imperative at a glance
4.3 Composition: The functional way
4.3.1 Working with side effects
4.3.2 Decomposing complex code
4.4 Currying and closures
4.4.1 Curried function application
4.4.2 The curry and composition dynamic duo
4.5 Working with immutable objects
4.6 Point-free coding
4.7 Imperative to functional transformation
4.8 Native function chains
Summary
5 Higher-kinded composition
5.1 Closing over data types
5.2 New Array APIs: {flat, flatMap}
5.2.1 Array.prototype.flat
5.2.2 Array.prototype.flatMap
5.3 The map/compose correspondence
5.4 Universal contracts
5.4.1 Functors
5.4.2 Monads
5.5 Contextual validation with higher-order functions
5.5.1 Kinds of ADTs
5.5.2 Choices
5.5.3 Modeling success and failure with the Validation monad
5.5.4 Composing with monads
5.5.5 Higher-kinded composition with Validation
5.5.6 Point-free coding with monads
5.5.7 Reducing complex data structures
5.5.8 Third-party integration
5.6 Higher-kinded composition with method extraction and dynamic binding
Summary
Part 3—Code
6 ECMAScript Modules
6.1 Past state of affairs
6.2 Module patterns
6.2.1 Object namespaces
6.2.2 Immediately Invoked Function Expressions (IIFEs)
6.2.3 IIFE mixins
6.2.4 Factory functions
6.3 Static vs. dynamic module systems
6.4 ESM basics
6.4.1 Path specifiers
6.4.2 Exporting
6.4.3 Importing
6.4.4 A new extension in town
6.5 Benefits of ESM for tooling
6.5.1 Dead-code elimination and tree-shaking
6.5.2 Faster property lookups
6.5.3 Type-friendliness
Summary
7 Hooked on metaprogramming
7.1 Common uses of metaprogramming in JavaScript
7.2 JavaScript symbols
7.3 Symbol registries
7.3.1 Local registry
7.3.2 Global registry
7.4 Practical application of symbols
7.4.1 Hidden properties
7.4.2 Interoperability
7.4.3 Serialization
7.5 Well-known symbols
7.5.1 @@toStringTag
7.5.2 @@isConcatSpreadable
7.5.3 @@species
7.5.4 @@toPrimitive
7.5.5 @@iterator
7.6 Dynamic introspection and weaving
7.6.1 Proxy objects
7.6.2 The Reflect API
7.6.3 Additional use cases
7.7 Implementing method decorators
Summary
Part 4—Data
8 Linear async flows
8.1 Architecture at a glance
8.2 JavaScript as promised
8.2.1 Principle of data locality
8.2.2 Are promises algebraic?
8.2.3 Fluent chaining
8.2.4 Promises in the wild
8.3 API review: Promise combinators
8.3.1 Promise.all
8.3.2 Promise.race
8.3.3 Promise.allSettled
8.3.4 Promise.any
8.4 async made easy
8.5 async iteration
8.6 Top-level await
Summary
9 Streams programming
9.1 Iterables and Iterators
9.1.1 Iterable protocol
9.1.2 Iterator protocol
9.1.3 Examples
9.2 Generators
9.2.1 To return or to yield
9.2.2 Creating iterable objects
9.2.3 Async generators
9.3 Working with data streams
9.3.1 What is a stream?
9.3.2 Implementing a streamable array
9.4 Welcoming a new native: Observable
9.4.1 What is an Observable?
9.4.2 Creating custom observables
9.4.3 Building your own reactive toolkit
9.4.4 Observable mixin extension
9.4.5 Representing push streams with generators
9.4.6 Pipeable operators
9.4.7 Streamifying objects
9.4.8 Dynamic streamification
9.5 Closing thoughts
Summary
Appendix A—Configuring Babel
Appendix B—Typed JavaScript
B.1 First, what?
B.2 Benefits and drawbacks of statically typed JavaScript
B.3 Type annotations
B.3.1 Class types
B.3.2 Interface types
B.3.3 Object types
B.3.4 Function types
B.3.5 Generic types
B.3.6 Union types
index
Symbols
A
B
C
D
E
F
G
H
I
J
L
M
N
O
P
Q
R
S
T
U
V
W
Y

The Joy of JavaScript [1 ed.]
 1617295868, 9781617295867

  • Commentary
  • Vector PDF
  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up