Atnaujinkite slapukų nuostatas

El. knyga: JavaScript - The New Toys: The New Toys [Wiley Online]

(Farsight Software)
  • Formatas: 608 pages
  • Išleidimo metai: 27-Aug-2020
  • Leidėjas: Wrox Press
  • ISBN-10: 1119367905
  • ISBN-13: 9781119367901
Kitos knygos pagal šią temą:
  • Wiley Online
  • Kaina: 42,29 €*
  • * this price gives unlimited concurrent access for unlimited time
  • Formatas: 608 pages
  • Išleidimo metai: 27-Aug-2020
  • Leidėjas: Wrox Press
  • ISBN-10: 1119367905
  • ISBN-13: 9781119367901
Kitos knygos pagal šią temą:
All of JavaScript's newest features, in depth, made easy to understand.

JavaScript is a rapidly changing language and it can be challenging to keep up with all the new toys being added. JavaScript: The New Toys explores the newest features of the world's most popular programming language while also showing readers how to track what's coming next. After setting the stage by covering who manages the process of improving JavaScript, how new features get introduced, terminology, and a high-level overview of new features, it details each new or updated item in depth, with example uses, possible pitfalls, and expert recommendations for updating old habits in light of new features.  JavaScript: The New Toys:





Covers all the additions to JavaScript in ES2015-ES2020 plus a preview of what's coming next Explores the latest syntax: nullish coalescing, optional chaining, let and const, class syntax, private methods, private fields, new.target, numeric separators, BigInt, destructuring, default parameters, arrow functions, async functions, await, generator functions, ... (rest and spread), template literals, binary and octal literals, ** (exponentiation), computed property/method names, for-of, for-await-of, shorthand properties, and others Details the new features and patterns including modules, promises, iteration, generators, Symbol, Proxy, reflection, typed arrays, Atomics, shared memory, WeakMap, WeakSet, and more Highlights common pitfalls and explains how to avoid them Shows how to follow the improvements process and even participate in the process yourself Explains how to use new features even before they're widely supported

With its comprehensive coverage and friendly, accessible style, JavaScript: The New Toys provides an invaluable resource for programmers everywhere, whether they work in web development, Node.js, Electron, Windows Universal Apps, or another JavaScript environment.
Introduction xxxi
Chapter 1 The New Toys In Es2015--Es2020, And Beyond
1(1)
Definitions, Who's Who, and Terminology
2(2)
Ecma? ECMAScript? TC39?
2(1)
ES6? ES7? ES2015? ES2020?
2(1)
JavaScript "Engines," Browsers, and Others
3(1)
What Are the "New Toys"?
4(2)
How Do New Toys Get Created?
6(3)
Who's in Charge
6(1)
The Process
7(1)
Getting Involved
8(1)
Keeping Up with the New Toys
9(1)
Using Today's Toys in Yesterday's Environments, and Tomorrow's toys Today
10(5)
Transpiling an Example with Babel
11(4)
Review
15(2)
Chapter 2 Block-Scoped Declarations: Let And Const
17(22)
An Introduction to let and const
18(1)
True Block Scope
18(1)
Repeated Declarations Are an Error
19(1)
Hoisting and the Temporal Dead Zone
20(2)
A New Kind of Global
22(2)
const: Constants for JavaScript
24(2)
Const Basics
24(1)
Objects Referenced by a const Are Still Mutable
25(1)
Block Scope in Loops
26(10)
The "Closures in Loops" Problem
26(2)
Bindings: How Variables, Constants, and Other Identifiers Work
28(5)
While and do-while Loops
33(1)
Performance Implications
34(1)
Const in Loop Blocks
35(1)
Const in for-in Loops
36(1)
Old Habits to New
36(3)
Use const or let Instead of var
36(1)
Keep Variables Narrowly Scoped
37(1)
Use Block Scope Instead of Inline Anonymous Functions
37(2)
Chapter 3 New Function Features
39(26)
Arrow Functions and Lexical this, super, etc.
40(5)
Arrow Function Syntax
40(4)
Arrow Functions and Lexical this
44(1)
Arrow Functions Cannot Be Constructors
45(1)
Default Parameter Values
45(5)
Defaults Are Expressions
46(1)
Defaults Are Evaluated in Their Own Scope
47(2)
Defaults Don't Add to the Arity of the Function
49(1)
"Rest" Parameters
50(2)
Trailing Commas in Parameter Lists and Function Calls
52(1)
The Function name Property
53(2)
Function Declarations in Blocks
55(5)
Function Declarations in Blocks: Standard Semantics
57(1)
Function Declarations in Blocks: Legacy Web Semantics
58(2)
Old Habits to New
60(5)
Use Arrow Functions Instead of Various this Value Workarounds
60(1)
Use Arrow Functions for Callbacks When Not Using this or arguments
61(1)
Consider Arrow Functions Elsewhere As Well
61(1)
Don't Use Arrow Functions When the Caller Needs to Control the Value of this
62(1)
Use Default Parameter Values Rather Than Code Providing Defaults
62(1)
Use a Rest Parameter Instead of the arguments Keyword
63(1)
Consider Trailing Commas If Warranted
63(2)
Chapter 4 Classes
65(40)
What Is a Class?
66(1)
Introducing the New class Syntax
66(9)
Adding a Constructor
68(2)
Adding Instance Properties
70(1)
Adding a Prototype Method
70(2)
Adding a Static Method
72(1)
Adding an Accessor Property
73(1)
Computed Method Names
74(1)
Comparing with the Older Syntax
75(2)
Creating Subclasses
77(20)
The super Keyword
81(1)
Writing Subclass Constructors
81(2)
Inheriting and Accessing Superclass Prototype Properties and Methods
83(3)
Inheriting Static Methods
86(2)
Super in Static Methods
88(1)
Methods Returning New Instances
88(5)
Subclassing Built-ins
93(1)
Where super Is Available
94(3)
Leaving Off Object.prototype
97(1)
new.target
98(3)
Class Declarations vs. class Expressions
101(2)
Class Declarations
101(1)
Class Expressions
102(1)
More to Come
103(1)
Old Habits to New
104(1)
Use class When Creating Constructor Functions
104(1)
Chapter 5 New Object Features
105(26)
Computed Property Names
106(1)
Shorthand Properties
107(1)
Getting and Setting an Object's Prototype
107(2)
Object.setPrototypeOf
107(1)
The_proto_Property on Browsers
108(1)
The_proto_Literal Property Name on Browsers
109(1)
Method Syntax, and super Outside Classes
109(3)
Symbol
112(8)
Why Symbols?
112(2)
Creating and Using Symbols
114(1)
Symbols Are Not for Privacy
115(1)
Global Symbols
115(4)
Well-Known Symbols
119(1)
New Object Functions
120(3)
Object.assign
120(1)
Object, is
121(1)
Object.values
122(1)
Object.entries
122(1)
Object.from Entries
122(1)
Object.getOwnPropertySymbols
122(1)
Object.getOwnPropertyDescriptors
123(1)
Symbol.toPrimitive
123(2)
Property Order
125(2)
Property Spread Syntax
127(1)
Old Habits to New
128(3)
Use Computed Syntax When Creating Properties with Dynamic Names
128(1)
Use Shorthand Syntax When Initializing a Property from a Variable with the Same Name
128(1)
Use Object.assign instead of Custom "Extend" Functions or Copying All Properties Explicitly
129(1)
Use Spread Syntax When Creating a New Object Based on an Existing Object's Properties
129(1)
Use Symbol to Avoid Name Collision
129(1)
Use Object.getPrototypeOf/setPrototypeOf Instead of proto
129(1)
Use Method Syntax for Methods
130(1)
Chapter 6 Iterables, Iterators, For-Of, Iterable Spread, Generators
131(34)
Iterators, Iterables, the for-of Loop, and Iterable Spread Syntax
131(15)
Iterators and Iterables
132(1)
The for-of Loop: Using an Iterator Implicitly
132(1)
Using an Iterator Explicitly
133(2)
Stopping Iteration Early
135(1)
Iterator Prototype Objects
136(2)
Making Something Iterable
138(4)
Iterable Iterators
142(1)
Iterable Spread Syntax
143(1)
Iterators, for-of, and the DOM
144(2)
Generator Functions
146(17)
A Basic Generator Function Just Producing Values
147(1)
Using Generator Functions to Create Iterators
148(1)
Generator Functions As Methods
149(1)
Using a Generator Directly
150(1)
Consuming Values with Generators
151(4)
Using return in a Generator Function
155(1)
Precedence of the yield Operator
155(2)
The return and throw Methods: Terminating a Generator
157(1)
Yielding a Generator or Iterable: yield*
158(5)
Old Habits to New
163(2)
Use Constructs That Consume Iterables
163(1)
Use DOM Collection Iteration Features
163(1)
Use the Iterable and Iterator Interfaces
164(1)
Use Iterable Spread Syntax in Most Places You Used to Use Function.prototype.apply
164(1)
Use Generators
164(1)
Chapter 7 Destructuring
165(16)
Overview
165(1)
Basic Object Destructuring
166(3)
Basic Array (and Iterable) Destructuring
169(1)
Defaults
170(2)
Rest Syntax in Destructuring Patterns
172(1)
Using Different Names
173(1)
Computed Property Names
174(1)
Nested Destructuring
174(1)
Parameter Destructuring
175(3)
Destructuring in Loops
178(1)
Old Habits to New
179(2)
Use Destructuring When Getting Only Some Properties from an Object
179(1)
Use Destructuring for Options Objects
179(2)
Chapter 8 Promises
181(40)
Why Promises?
182(1)
Promise Fundamentals
182(4)
Overview
182(2)
Example
184(2)
Promises and "Thenables"
186(1)
Using an Existing Promise
186(15)
The then Method
187(1)
Chaining Promises
187(4)
Comparison with Callbacks
191(1)
The catch Method
192(2)
The finally Method
194(4)
Throw in then, catch, and finally Handlers
198(1)
The then Method with Two Arguments
199(2)
Adding Handlers to Already Settled Promises
201(1)
Creating Promises
202(5)
The Promise Constructor
203(2)
Promise.resolve
205(1)
Promise.reject
206(1)
Other Promise Utility Methods
207(3)
Promise.all
207(2)
Promise.race
209(1)
Promise.allSettled
209(1)
Promise.any
210(1)
Promise Patterns
210(4)
Handle Errors or Return the Promise
210(1)
Promises in Series
211(2)
Promises in Parallel
213(1)
Promise Anti-Patterns
214(4)
Unnecessary new Promise(/*...*/)
214(1)
Not Handling Errors (or Not Properly)
214(1)
Letting Errors Go Unnoticed When Converting a Callback API
214(1)
Implicitly Converting Rejection to Fulfillment
215(1)
Trying to Use Results Outside the Chain
216(1)
Using Do-Nothing Handlers
216(1)
Branching the Chain Incorrectly
217(1)
Promise Subclasses
218(1)
Old Habits to New
219(2)
Use Promises Instead of Success/Failure Callbacks
219(2)
Chapter 9 Asynchronous Functions, Iterators, And Generators
221(20)
Async Functions
222(10)
Async Functions Create Promises
224(1)
Await Consumes Promises
225(1)
Standard Logic Is Asynchronous When await Is Used
225(2)
Rejections Are Exceptions, Exceptions Are Rejections; Fulfillments Are Results, Returns Are Resolutions
227(2)
Parallel Operations in async Functions
229(1)
You Don't Need return await
230(1)
Pitfall: Using an async Function in an Unexpected Place
231(1)
Async Iterators, Iterables, and Generators
232(6)
Asynchronous Iterators
233(3)
Asynchronous Generators
236(2)
for-await-of
238(1)
Old Habits to New
238(3)
Use async Functions and await Instead of Explicit Promises and then/catch
238(3)
Chapter 10 Templates, Tag Functions, And New String Features
241(22)
Template Literals
241(9)
Basic Functionality (Untagged Template Literals)
242(1)
Template Tag Functions (Tagged Template Literals)
243(5)
String.raw
248(1)
Reusing Template Literals
249(1)
Template Literals and Automatic Semicolon Insertion
250(1)
Improved Unicode Support
250(5)
Unicode, and What Is a JavaScript String?
250(2)
Code Point Escape Sequence
252(1)
String.fromCodePoint
252(1)
String, prototype. codePointAt
252(1)
String.prototype.normalize
253(2)
Iteration
255(1)
New String Methods
256(3)
String.prototype.repeat
256(1)
String.prototype.startsWith, endsWith
256(1)
String.prototype.includes
257(1)
String.prototype.padStart, padEnd
257(1)
String.prototype.trimStart, trimEnd
258(1)
Updates to the match, split, search, and replace Methods
259(1)
Old Habits to New
260(3)
Use Template Literals Instead of String Concatenation (Where Appropriate)
260(1)
Use Tag Functions and Template Literals for DSLs Instead of Custom Placeholder Mechanisms
261(1)
Use String Iterators
261(2)
Chapter 11 New Array Features, Typed Arrays
263(30)
New Array Methods
264(12)
Array, of
264(1)
Array.from
264(2)
Array.prototype.keys
266(1)
Array.prototype.values
267(1)
Array.prototype.entries
268(1)
Array.prototype.copyWithin
269(2)
Array.prototype.find
271(2)
Array.prototype.findlndex
273(1)
Array.prototype.fill
273(1)
Common Pitfall: Using an Object As the Fill Value
273(1)
Array.prototype.includes
274(1)
Array.prototype.flat
275(1)
Array.prototype.flatMap
276(1)
Iteration, Spread, Destructuring
276(1)
Stable Array Sort
276(1)
Typed Arrays
277(15)
Overview
277(2)
Basic Use
279(1)
Value Conversion Details
280(2)
ArrayBuffer: The Storage Used by Typed Arrays
282(2)
Endianness (Byte Order)
284(2)
DataView: Raw Access to the Buffer
286(1)
Sharing an ArrayBuffer Between Arrays
287(1)
Sharing Without Overlap
287(1)
Sharing with Overlap
288(1)
Subclassing Typed Arrays
289(1)
Typed Array Methods
289(1)
Standard Array Methods
289(1)
%TypedArray%.prototype.set
290(1)
%TypedArray%.prototype.subarray
291(1)
Old Habits to New
292(1)
Use find and find Index to Search Arrays Instead of Loops (Where Appropriate)
292(1)
Use Array.fill to Fill Arrays Rather Than Loops
292(1)
Use readAsArrayBuffer Instead of readAsBinaryString
292(1)
Chapter 12 Maps And Sets
293(26)
Maps
293(7)
Basic Map Operations
294(2)
Key Equality
296(1)
Creating Maps from Iterables
297(1)
Iterating the Map Contents
297(2)
Subclassing Map
299(1)
Performance
300(1)
Sets
300(4)
Basic Set Operations
301(1)
Creating Sets from Iterables
302(1)
Iterating the Set Contents
302(1)
Subclassing Set
303(1)
Performance
304(1)
WeakMaps
304(10)
WeakMaps Are Not Iterable
305(1)
Use Cases and Examples
305(1)
Use Case: Private Information
305(2)
Use Case: Storing Information for Objects Outside Your Control
307(1)
Values Referring Back to the Key
308(6)
WeakSets
314(2)
Use Case: Tracking
314(1)
Use Case: Branding
315(1)
Old Habits to New
316(3)
Use Maps Instead of Objects for General-Purpose Maps
316(1)
Use Sets Instead of Objects for Sets
316(1)
Use WeakMaps for Storing Private Data Instead of Public Properties
317(2)
Chapter 13 Modules
319(46)
Introduction to Modules
319(1)
Module Fundamentals
320(11)
The Module Specifier
322(1)
Basic Named Exports
322(2)
Default Export
324(1)
Using Modules in Browsers
325(1)
Module Scripts Don't Delay Parsing
326(1)
The nomodule Attribute
327(1)
Module Specifiers on the Web
328(1)
Using Modules in Node.js
328(2)
Module Specifiers in Node.js
330(1)
Node.js is Adding More Module Features
331(1)
Renaming Exports
331(1)
Re-Exporting Exports from Another Module
332(1)
Renaming Imports
333(1)
Importing a Module's Namespace Object
333(1)
Exporting Another Module's Namespace Object
334(1)
Importing a Module Just for Side Effects
335(1)
Import and Export Entries
335(3)
Import Entries
335(1)
Export Entries
336(2)
Imports Are Live and Read-Only
338(2)
Module Instances Are Realm-Specific
340(1)
How Modules Are Loaded
341(7)
Fetching and Parsing
342(2)
Instantiation
344(2)
Evaluation
346(1)
Temporal Dead Zone (TDZ) Review
346(1)
Cyclic Dependencies and the TDZ
347(1)
Import/Export Syntax Review
348(2)
Export Varieties
348(2)
Import Varieties
350(1)
Dynamic Import
350(7)
Importing a Module Dynamically
351(1)
Dynamic Module Example
352(4)
Dynamic Import in Non-Module Scripts
356(1)
Tree Shaking
357(2)
Bundling
359(1)
Import Metadata
360(1)
Worker Modules
360(2)
Loading a Web Worker as a Module
360(1)
Loading a Node.js Worker as a Module
361(1)
A Worker Is in Its Own Realm
361(1)
Old Habits to New
362(3)
Use Modules Instead of Pseudo-Namespaces
362(1)
Use Modules Instead of Wrapping Code in Scoping Functions
363(1)
Use Modules to Avoid Creating Megalithic Code Files
363(1)
Convert CJS, AMD, and Other Modules to ESM
363(1)
Use a Well-Maintained Bundler Rather Than Going Homebrew
363(2)
Chapter 14 Reflection---Reflect And Proxy
365(32)
Reflect
365(6)
Reflect.apply
367(1)
Reflect.construct
367(1)
Reflect.ownKeys
368(1)
Reflect.get, Reflect.set
369(1)
Other Reflect Functions
370(1)
Proxy
371(24)
Example: Logging Proxy
373(8)
Proxy Traps
381(1)
Common Features
381(1)
The apply Trap
381(1)
The construct Trap
382(1)
The defineProperty Trap
382(2)
The deleteProperty Trap
384(1)
The get Trap
385(1)
The getOwnPropertyDescriptor Trap
386(1)
The getPrototypeOf Trap
387(1)
The has Trap
388(1)
The isExtensible Trap
388(1)
The ownKeys Trap
388(1)
The preventExtensions Trap
389(1)
The set Trap
389(1)
The setPrototypeOf Trap
390(1)
Example: Hiding Properties
391(3)
Revocable Proxies
394(1)
Old Habits to New
395(2)
Use Proxies Rather Than Relying on Consumer Code Not to Modify API Objects
395(1)
Use Proxies to Separate Implementation Code from Instrumenting Code
395(2)
Chapter 15 Regular Expression Updates
397(20)
The Flags Property
398(1)
New Flags
398(2)
The Sticky Flag (y)
398(1)
The Unicode Flag (u)
399(1)
The "Dot All" Flag (s)
400(1)
Named Capture Groups
400(5)
Basic Functionality
400(4)
Backreferences
404(1)
Replacement Tokens
405(1)
Lookbehind Assertions
405(3)
Positive Lookbehind
405(1)
Negative Lookbehind
406(1)
Greediness Is Right-to-Left in Lookbehinds
407(1)
Capture Group Numbering and References
407(1)
Unicode Features
408(5)
Code Point Escapes
408(1)
Unicode Property Escapes
409(4)
Old Habits to New
413(4)
Use the Sticky Flag (y) Instead of Creating Substrings and Using & When Parsing
413(1)
Use the Dot All Flag (s) Instead of Using Workarounds to Match All Characters (Including Line Breaks)
414(1)
Use Named Capture Groups Instead of Anonymous Ones
414(1)
Use Lookbehinds Instead of Various Workarounds
415(1)
Use Code Point Escapes Instead of Surrogate Pairs in Regular Expressions
415(1)
Use Unicode Patterns Instead of Workarounds
415(2)
Chapter 16 Shared Memory
417(44)
Introduction
417(1)
Here There Be Dragons!
418(1)
Browser Support
418(2)
Shared Memory Basics
420(6)
Critical Sections, Locks, and Condition Variables
420(2)
Creating Shared Memory
422(4)
Memory Is Shared, Not Objects
426(1)
Race Conditions, Out-of-Order Stores, Stale Values, Tearing, and More
427(2)
The Atomics Object
429(5)
Low-Level Atomics Features
432(1)
Using Atomics to Suspend and Resume Threads
433(1)
Shared Memory Example
434(21)
Here There Be Dragons! (Again)
455(5)
Old Habits to New
460(1)
Use Shared Blocks Rather Than Exchanging Large Data Blocks Repeatedly
460(1)
Use Atomics.wait and Atomics.notify Instead of Breaking Up Worker Jobs to Support the Event Loop (Where Appropriate)
460(1)
Chapter 17 Miscellany
461(32)
Biglnt
462(3)
Creating a BigInt
462(1)
Explicit and Implicit Conversion
463(1)
Performance
464(1)
Biglnt64Array and BigUint64Array
465(1)
Utility Functions
465(1)
New Integer Literals
465(2)
Binary Integer Literals
465(1)
Octal Integer Literals, Take II
466(1)
New Math Methods
467(1)
General Math Functions
467(1)
Low-Level Math Support Functions
468(1)
Exponentiation Operator
468(2)
Date.prototype.toString Change
470(1)
Function.prototype.toString Change
471(1)
Number Additions
471(3)
"Safe" Integers
471(1)
Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER
472(1)
Number.isSafeInteger
472(1)
Number.isInteger
473(1)
Number.isFinite, Number.isNaN
473(1)
Number.parseInt, Number.parseFloat
473(1)
Number.EPSILON
473(1)
Symbol.isConcatSpreadable
474(1)
Various Syntax Tweaks
475(4)
Nullish Coalescing
475(1)
Optional Chaining
476(2)
Optional catch Bindings
478(1)
Unicode Line Breaks in JSON
478(1)
Well-Formed JSON from JSON.stringify
479(1)
Various Standard Library / Global Additions
479(3)
Symbol.haslnstance
479(1)
Symbol.unscopables
479(1)
globalThis
480(1)
Symbol description Property
481(1)
String.prototype.matchAII
481(1)
Annex B: Browser-Only Features
482(6)
HTML-Like Comments
483(1)
Regular Expression Tweaks
483(1)
Control Character Escape (\cX) Extension
483(1)
Tolerating Invalid Sequences
484(1)
RegExp.prototype.compile
484(1)
Additional Built-In Properties
484(1)
Additional Object Properties
484(1)
Additional String Methods
485(1)
Various Bits of Loosened or Obscure Syntax
486(1)
When document.all Isn't There ... or Is It?
487(1)
Tail Call Optimization
488(3)
Old Habits to New
491(2)
Use Binary Literals
491(1)
Use New Math Functions Instead of Various Math Workarounds
491(1)
Use Nullish Coalescing for Defaults
491(1)
Use Optional Chaining Instead of & Checks
491(1)
Leave the Error Binding (e) Off of "catch (e)" When Not Using It
492(1)
Use the Exponentiation Operator Rather Than Math.pow
492(1)
Chapter 18 Upcoming Class Features
493(24)
Public and Private Class Fields, Methods, and Accessors
493(21)
Public Field (Property) Definitions
494(5)
Private Fields
499(8)
Private Instance Methods and Accessors
507(1)
Private Methods
507(4)
Private Accessors
511(1)
Public Static Fields, Private Static Fields, and Private Static Methods
511(1)
Public Static Fields
511(2)
Private Static Fields
513(1)
Private Static Methods
513(1)
Old Habits to New
514(3)
Use Property Definitions Instead of Creating Properties in the Constructor (Where Appropriate)
514(1)
Use Private Fields Instead of Prefixes (Where Appropriate)
514(1)
Use Private Methods Instead of Functions Outside the Class for Private Operations
514(3)
Chapter 19 A Look Ahead ...
517(22)
Top-Level await
518(7)
Overview and Use Cases
518(2)
Example
520(4)
Error Handling
524(1)
WeakRefs and Cleanup Callbacks
525(8)
WeakRefs
525(3)
Cleanup Callbacks
528(5)
RegExp Match Indices
533(2)
String.prototype.replaceAII
535(1)
Atomics asyncWait
535(1)
Various Syntax Tweaks
536(1)
Numeric Separators
536(1)
Hashbang Support
537(1)
Legacy Deprecated RegExp Features
537(1)
Thank You for Reading!
538(1)
Appendix: Fantastic Features And Where To Find Them 539(18)
Index 557
About the author

T.J. Crowder is a software engineer with 30 years of experience, including over 15 years of professional work in JavaScript. He runs Farsight Software, a software contracting and product company. He's often found helping people on Stack Overflow, where he's a top 10 all-time contributor and the top JavaScript contributor. When not working or writing, heno, sorry, he's always working or writing or spending time with his wonderful, supportive wife and fantastic son.

Visit us at www.wiley.com for free code samples.