Deep jаvascript: Theory and techniques

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Rauschmayer Axel
Year: 2020

Language: English
Commentary: True PDF
Pages: 226

I Frontmatter
About this book
Where is the homepage of this book?
What is in this book?
What do I get for my money?
How can I preview the content?
How do I report errors?
Tips for reading
Notations and conventions
Acknowledgements
II Types, values, variables
Type coercion in JavaScript
What is type coercion?
Operations that help implement coercion in the ECMAScript specification
Intermission: expressing specification algorithms in JavaScript
Example coercion algorithms
Operations that coerce
Glossary: terms related to type conversion
The destructuring algorithm
Preparing for the pattern matching algorithm
The pattern matching algorithm
Empty object patterns and Array patterns
Applying the algorithm
A detailed look at global variables
Scopes
Lexical environments
The global object
In browsers, globalThis does not point directly to the global object
The global environment
Conclusion: Why does JavaScript have both normal global variables and the global object?
Further reading and sources of this chapter
% is a remainder operator, not a modulo operator (bonus)
Remainder operator rem vs. modulo operator mod
An intuitive understanding of the remainder operation
An intuitive understanding of the modulo operation
Similarities and differences between rem and mod
The equations behind remainder and modulo
Where are rem and mod used in programming languages?
Further reading and sources of this chapter
III Working with data
Copying objects and Arrays
Shallow copying vs. deep copying
Shallow copying in JavaScript
Deep copying in JavaScript
Further reading
Updating data destructively and non-destructively
Examples: updating an object destructively and non-destructively
Examples: updating an Array destructively and non-destructively
Manual deep updating
Implementing generic deep updating
The problems of shared mutable state and how to avoid them
What is shared mutable state and why is it problematic?
Avoiding sharing by copying data
Avoiding mutations by updating non-destructively
Preventing mutations by making data immutable
Libraries for avoiding shared mutable state
IV OOP: object property attributes
Property attributes: an introduction
The structure of objects
Property descriptors
Retrieving descriptors for properties
Defining properties via descriptors
Object.create(): Creating objects via descriptors
Use cases for Object.getOwnPropertyDescriptors()
Omitting descriptor properties
What property attributes do built-in constructs use?
API: property descriptors
Further reading
Protecting objects from being changed
Levels of protection: preventing extensions, sealing, freezing
Preventing extensions of objects
Sealing objects
Freezing objects
Further reading
Properties: assignment vs. definition
Assignment vs. definition
Assignment and definition in theory (optional)
Definition and assignment in practice
Which language constructs use definition, which assignment?
Further reading and sources of this chapter
Enumerability of properties
How enumerability affects property-iterating constructs
The enumerability of pre-defined and created properties
Use cases for enumerability
Conclusion
V OOP: techniques
Techniques for instantiating classes
The problem: initializing a property asynchronously
Solution: Promise-based constructor
Solution: static factory method
Subclassing a Promise-based constructor (optional)
Conclusion
Further reading
Copying instances of classes: .clone() vs. copy constructors
.clone() methods
Static factory methods
Acknowledgements
Immutable wrappers for collections
Wrapping objects
An immutable wrapper for Maps
An immutable wrapper for Arrays
VI Regular expressions
Regular expressions: lookaround assertions by example
Cheat sheet: lookaround assertions
Warnings for this chapter
Example: Specifying what comes before or after a match (positive lookaround)
Example: Specifying what does not come before or after a match (negative lookaround)
Interlude: pointing lookaround assertions inward
Example: match strings not starting with 'abc'
Example: match substrings that do not contain '.mjs'
Example: skipping lines with comments
Example: smart quotes
Acknowledgements
Further reading
Composing regular expressions via re-template-tag (bonus)
The basics
A tour of the features
Why is this useful?
re and named capture groups
VII Miscellaneous topics
Exploring Promises by implementing them
Refresher: states of Promises
Version 1: Stand-alone Promise
Version 2: Chaining .then() calls
Convenience method .catch()
Omitting reactions
The implementation
Version 3: Flattening Promises returned from .then() callbacks
Version 4: Exceptions thrown in reaction callbacks
Version 5: Revealing constructor pattern
Metaprogramming with Proxies (early access)
Overview
Programming versus metaprogramming
Proxies explained
Use cases for Proxies
The design of the Proxy API
FAQ: Proxies
Reference: the Proxy API
Conclusion
Further reading
The property .name of functions (bonus)
Names of functions
Constructs that provide names for functions
Things to look out for with names of functions
Changing the names of functions
The function property .name in the ECMAScript specification