0% found this document useful (0 votes)
29 views

Ebooks File JavaScript: The New Toys T. J. Crowder All Chapters

ebook

Uploaded by

dorrenmasha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Ebooks File JavaScript: The New Toys T. J. Crowder All Chapters

ebook

Uploaded by

dorrenmasha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

Full download ebook at ebookmass.

com

JavaScript: The New Toys T. J. Crowder

For dowload this book click link below


https://ebookmass.com/product/javascript-the-new-
toys-t-j-crowder/

OR CLICK BUTTON

DOWLOAD EBOOK

Download more ebook from https://ebookmass.com


More products digital (pdf, epub, mobi) instant
download maybe you interests ...

JavaScript T. J. Crowder

https://ebookmass.com/product/javascript-t-j-crowder/

Ethnopolitics in the New Europe John T. Ishiyama

https://ebookmass.com/product/ethnopolitics-in-the-new-europe-
john-t-ishiyama/

Understanding the Physics of Toys S Rajasekar

https://ebookmass.com/product/understanding-the-physics-of-toys-
s-rajasekar/

New Perspectives on HTML5, CSS3, and JavaScript 6th


Edition Patrick Carey

https://ebookmass.com/product/new-perspectives-on-html5-css3-and-
javascript-6th-edition-patrick-carey/
Toys and Communication 1st Edition Luísa Magalhães

https://ebookmass.com/product/toys-and-communication-1st-edition-
luisa-magalhaes/

The Marketing of Children’s Toys 1st ed. 2021 Edition


Rebecca C. Hains

https://ebookmass.com/product/the-marketing-of-childrens-
toys-1st-ed-2021-edition-rebecca-c-hains/

Technopopulism: The New Logic of Democratic Politics


Christopher J. Bickerton

https://ebookmass.com/product/technopopulism-the-new-logic-of-
democratic-politics-christopher-j-bickerton/

Javascript: Crash Course - The Complete Beginners Guide


To Learning JavaScript Programming In No Time!
(Angularjs, jQuery, JavaScript Visually) Nathaniel Hill

https://ebookmass.com/product/javascript-crash-course-the-
complete-beginners-guide-to-learning-javascript-programming-in-
no-time-angularjs-jquery-javascript-visually-nathaniel-hill/

Forging a New South: The Life of General John T. Wilder


1st Edition Nicely

https://ebookmass.com/product/forging-a-new-south-the-life-of-
general-john-t-wilder-1st-edition-nicely/
JavaScript®
THE NEW TOYS

T.J. Crowder

www.allitebooks.com
JAVASCRIPT®
THE NEW TOYS

INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi

CHAPTER 1 The New Toys in ES2015–ES2020, and Beyond . . . . . . . . . . . . . . . . . . 1


CHAPTER 2 Block-Scoped Declarations: let and const . . . . . . . . . . . . . . . . . . . . . 17
CHAPTER 3 New Function Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
CHAPTER 4 Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
CHAPTER 5 New Object Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
CHAPTER 6 Iterables, Iterators, for-of, Iterable Spread, Generators . . . . . . . . . 131
CHAPTER 7 Destructuring. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
CHAPTER 8 Promises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
CHAPTER 9 Asynchronous Functions, Iterators, and Generators . . . . . . . . . . . . 221
CHAPTER 10 Templates, Tag Functions, and New String Features. . . . . . . . . . . . 241
CHAPTER 11 New Array Features, Typed Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . 263
CHAPTER 12 Maps and Sets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
CHAPTER 13 Modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
CHAPTER 14 Reflection—Reflect and Proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
CHAPTER 15 Regular Expression Updates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
CHAPTER 16 Shared Memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
CHAPTER 17 Miscellany. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
CHAPTER 18 Upcoming Class Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
CHAPTER 19 A Look Ahead … . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
APPENDIX Fantastic Features and Where to Find Them . . . . . . . . . . . . . . . . . . 539

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557

www.allitebooks.com
JavaScript®
The New Toys

www.allitebooks.com
JavaScript®: The New Toys
Copyright © 2020 by Thomas Scott “T.J.” Crowder

Published simultaneously in Canada

ISBN: 978-1-119-36797-6
ISBN: 978-1-119-36797-0 (ebk)
ISBN: 978-1-119-36796-3 (ebk)

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of
the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through
payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923,
(978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions
Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online
at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect
to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without
limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional
materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the
understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional
assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author
shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation
and/or a potential source of further information does not mean that the author or the publisher endorses the information the
organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web
sites listed in this work may have changed or disappeared between when this work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department within the United
States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print
versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD
that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com.
For more information about Wiley products, visit www.wiley.com.

Library of Congress Control Number: 2018965303

Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries,
and may not be used without written permission. JavaScript is a registered trademark of Oracle America, Inc. All other
trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or
vendor mentioned in this book.

www.allitebooks.com
To Wendy and James, who’ve met late nights and
working weekends with unstinting support and
loving encouragement.

www.allitebooks.com
ABOUT THE AUTHOR

T.J. CROWDER is a software engineer with 30 years of professional experience, at least half that time
working with JavaScript. He runs Farsight Software, a UK software consulting and product company.
As one of the top 10 contributors on Stack Overflow and the top contributor in the JavaScript tag, he
likes to use what he’s learned to help others with the technical challenges they’re facing, with an
emphasis not just on imparting knowledge, but on helping with the process of solving problems.
T.J. started programming in his early teens in California, playing around with the Apple II and
Sinclair ZX-80 and -81 using BASIC and assembly language. He got his first proper job with comput-
ers many years later, working a technical support position for a company with a PC (DOS) product
for court reporters. While working support, he taught himself C from the TurboC manuals in the
office, reverse-engineered the company’s undocumented, compressed binary file format, and used
that knowledge to create a much-requested feature for the product in his spare time (one the com-
pany soon started shipping). Before long the development department took him in and over the next
several years gave him the opportunity, resources, and responsibility to grow into a programmer and,
eventually, into their lead engineer, creating various products including their first Windows product.
At his next company he took on a professional services and developer education role that saw him
customizing the company’s enterprise product on-site for clients (using VB6, JavaScript, and HTML)
and teaching training classes to the clients’ developers; eventually he was writing the training classes.
A move from the U.S. to London put him back in a straight development role where he was able to
increase his software design, SQL, Java, and JavaScript skills before branching out into independent
contracting.
Since then through circumstance he’s been doing primarily closed-source remote development work
for a variety of companies and organizations (a NATO agency, a UK local government authority, and
various private firms) working primarily in JavaScript, SQL, C#, and (recently) TypeScript. The desire
for community led him first to the PrototypeJS mailing list back in the day, then to Stack Overflow,
and now to various platforms.
English and American by birth, American by upbringing, T.J. lives in a village in central England with
his wife and son.
ABOUT THE TECHNICAL EDITOR

CHAIM KRAUSE is an expert computer programmer with over thirty years of experience to prove it.
He has worked as a lead tech support engineer for ISPs as early as 1995, as a senior developer sup-
port engineer with Borland for Delphi, and has worked in Silicon Valley for over a decade in various
roles, including technical support engineer and developer support engineer. He is currently a military
simulation specialist for the US Army’s Command and General Staff College, working on projects
such as developing serious games for use in training exercises. He has also authored several video
training courses on Linux topics, and has been a technical reviewer for over two dozen books.
ABOUT THE TECHNICAL PROOFREADER

MARCIA K. WILBUR is a technical communicator consulting in the semiconductor field, focusing on


Industrial IoT (IIoT) and AI. Marcia holds degrees in computer science, technical communication,
and information technology. As Copper Linux User Group president, she is heavily involved with the
maker community leading West Side Linux + Pi and the East Valley leading regular Raspberry Pi, Bea-
glebone, Banana Pi/Pro, and ESP8266 Projects including home automation, gaming consoles, surveil-
lance, network, multimedia, and other “pi fun”.
ACKNOWLEDGMENTS

“I wrote a book” is almost never an accurate statement.


Sure, all the unquoted words in the book are mine. But none of them would be here if it weren’t for
others—others offering support, offering perspective, offering encouragement; others reviewing drafts
to help cut the chaff and reveal the nugget of usefulness buried within; others asking questions in a
variety of forums over the years, giving me the opportunity to practice the art and craft of explaining
what meager knowledge I’ve been able to pick up; others answering my questions, directly and by
pointing to resources; others helping hone my language and improve my wordcraft.
All of which waffle means: I owe thanks to a lot of people. This is my first proper book, and I made
just about every mistake there is to make. The people below caught and corrected as many of them as
they could. Any that remain are mine.
Primarily, thanks to my wife Wendy for her amazing support, for being an endless and willing source
of strength and font of encouragement, for bringing me back when (as James Taylor puts it) I find
myself careening in places where I should not let me go.
Thanks to my son James for putting up with Dad being squirrelled away in the office so much.
Thanks to my mother Virginia and father Norman for instilling in me a love of language, learning,
reading, and writing. These are gifts that last a lifetime.
Thanks to my best friend Jock for being an ever-patient sounding board and source of encourage-
ment—and, for that matter, for having been instrumental in getting me interested in programming in
the first place.
Thanks to all of my editors and reviewers at Wiley & Sons: Jim Minatel and Pete Gaughan for sup-
porting and maintaining the project even in the face of a frustrating author; David Clark and Chaim
Krause for editorial and technical review; Kim Cofer for her excellent copyediting and help with
grammar, syntax, and clarity; to Nancy Bell for her proofreading; to the artists and compositors in
the production department; and to all the others I’ve failed to mention by name for supporting all
aspects of the project.
Thanks to Andreas Bergmaier for helping me keep my technical T’s crossed and I’s dotted—Andreas’
keen eye and deep understanding were a huge help throughout the book.
Thanks to TC39 member Daniel Ehrenberg of Igalia for helping me better understand how TC39
works, and for kindly reviewing and helping me refine Chapter 1. His gentle corrections, input, and
insight dramatically improved that chapter.
Thanks to TC39 member Lars T. Hansen of Mozilla (co-author of the shared memory and atomics
JavaScript proposal) for his kind and invaluable help with getting the details and scope right in Chap-
ter 16. His deep knowledge and perspective made all the difference there.
And finally, thanks to you, dear reader, for giving your time and attention to my efforts here. I hope it
serves you well.
CONTENTS

INTRODUCTION xxxi

CHAPTER 1: THE NEW TOYS IN ES2015–ES2020, AND BEYOND 1

Definitions, Who’s Who, and Terminology 2


Ecma? ECMAScript? TC39? 2
ES6? ES7? ES2015? ES2020? 2
JavaScript “Engines,” Browsers, and Others 3
What Are the “New Toys”? 4
How Do New Toys Get Created? 6
Who’s in Charge 6
The Process 7
Getting Involved 8
Keeping Up with the New Toys 9
Using Today’s Toys in Yesterday’s Environments,
and Tomorrow’s Toys Today 10
Transpiling an Example with Babel 11
Review 15

CHAPTER 2: BLOCK-SCOPED DECLARATIONS: LET AND CONST 17

An Introduction to let and const 18


True Block Scope 18
Repeated Declarations Are an Error 19
Hoisting and the Temporal Dead Zone 20
A New Kind of Global 22
const: Constants for JavaScript 24
const Basics 24
Objects Referenced by a const Are Still Mutable 25
Block Scope in Loops 26
The “Closures in Loops” Problem 26
Bindings: How Variables, Constants, and Other Identifiers Work 28
while and do-while Loops 33
Performance Implications 34
const in Loop Blocks 35
const in for-in Loops 36
Contents

Old Habits to New 36


Use const or let Instead of var 36
Keep Variables Narrowly Scoped 37
Use Block Scope Instead of Inline Anonymous Functions 37

CHAPTER 3: NEW FUNCTION FEATURES 39

Arrow Functions and Lexical this, super, etc. 40


Arrow Function Syntax 40
Arrow Functions and Lexical this 44
Arrow Functions Cannot Be Constructors 45
Default Parameter Values 45
Defaults Are Expressions 46
Defaults Are Evaluated in Their Own Scope 47
Defaults Don’t Add to the Arity of the Function 49
“Rest” Parameters 50
Trailing Commas in Parameter Lists and Function Calls 52
The Function name Property 53
Function Declarations in Blocks 55
Function Declarations in Blocks: Standard Semantics 57
Function Declarations in Blocks: Legacy Web Semantics 58
Old Habits to New 60
Use Arrow Functions Instead of Various this Value Workarounds 60
Use Arrow Functions for Callbacks When Not Using this or arguments 61
Consider Arrow Functions Elsewhere As Well 61
Don’t Use Arrow Functions When the Caller Needs to Control
the Value of this 62
Use Default Parameter Values Rather Than Code Providing Defaults 62
Use a Rest Parameter Instead of the arguments Keyword 63
Consider Trailing Commas If Warranted 63

CHAPTER 4: CLASSES 65

What Is a Class? 66
Introducing the New class Syntax 66
Adding a Constructor 68
Adding Instance Properties 70
Adding a Prototype Method 70
Adding a Static Method 72
Adding an Accessor Property 73
Computed Method Names 74
Comparing with the Older Syntax 75

xviii
Contents

Creating Subclasses 77
The super Keyword 81
Writing Subclass Constructors 81
Inheriting and Accessing Superclass Prototype Properties and Methods 83
Inheriting Static Methods 86
super in Static Methods 88
Methods Returning New Instances 88
Subclassing Built-ins 93
Where super Is Available 94
Leaving Off Object.prototype 97
new.target 98
class Declarations vs. class Expressions 101
class Declarations 101
class Expressions 102
More to Come 103
Old Habits to New 104
Use class When Creating Constructor Functions 104

CHAPTER 5: NEW OBJECT FEATURES 105

Computed Property Names 106


Shorthand Properties 107
Getting and Setting an Object’s Prototype 107
Object.setPrototypeOf 107
The __proto__ Property on Browsers 108
The __proto__ Literal Property Name on Browsers 109
Method Syntax, and super Outside Classes 109
Symbol 112
Why Symbols? 112
Creating and Using Symbols 114
Symbols Are Not for Privacy 115
Global Symbols 115
Well-Known Symbols 119
New Object Functions 120
Object.assign 120
Object.is 121
Object.values 122
Object.entries 122
Object.fromEntries 122
Object.getOwnPropertySymbols 122
Object.getOwnPropertyDescriptors 123
Symbol.toPrimitive 123
Property Order 125
xix
Contents

Property Spread Syntax 127


Old Habits to New 128
Use Computed Syntax When Creating Properties
with Dynamic Names 128
Use Shorthand Syntax When Initializing a Property
from a Variable with the Same Name 128
Use Object.assign instead of Custom “Extend”
Functions or Copying All Properties Explicitly 129
Use Spread Syntax When Creating a New Object
Based on an Existing Object’s Properties 129
Use Symbol to Avoid Name Collision 129
Use Object.getPrototypeOf/setPrototypeOf Instead of __proto__ 129
Use Method Syntax for Methods 130

CHAPTER 6: ITERABLES, ITERATORS, FOR-OF, ITERABLE


SPREAD, GENERATORS 131

Iterators, Iterables, the for-of Loop, and Iterable Spread Syntax 131
Iterators and Iterables 132
The for-of Loop: Using an Iterator Implicitly 132
Using an Iterator Explicitly 133
Stopping Iteration Early 135
Iterator Prototype Objects 136
Making Something Iterable 138
Iterable Iterators 142
Iterable Spread Syntax 143
Iterators, for-of, and the DOM 144
Generator Functions 146
A Basic Generator Function Just Producing Values 147
Using Generator Functions to Create Iterators 148
Generator Functions As Methods 149
Using a Generator Directly 150
Consuming Values with Generators 151
Using return in a Generator Function 155
Precedence of the yield Operator 155
The return and throw Methods: Terminating a Generator 157
Yielding a Generator or Iterable: yield* 158
Old Habits to New 163
Use Constructs That Consume Iterables 163
Use DOM Collection Iteration Features 163
Use the Iterable and Iterator Interfaces 164
Use Iterable Spread Syntax in Most Places You Used
to Use Function.prototype.apply 164
Use Generators 164
xx
Contents

CHAPTER 7: DESTRUCTURING 165

Overview 165
Basic Object Destructuring 166
Basic Array (and Iterable) Destructuring 169
Defaults 170
Rest Syntax in Destructuring Patterns 172
Using Different Names 173
Computed Property Names 174
Nested Destructuring 174
Parameter Destructuring 175
Destructuring in Loops 178
Old Habits to New 179
Use Destructuring When Getting Only Some Properties
from an Object 179
Use Destructuring for Options Objects 179

CHAPTER 8: PROMISES 181

Why Promises? 182


Promise Fundamentals 182
Overview 182
Example 184
Promises and “Thenables” 186
Using an Existing Promise 186
The then Method 187
Chaining Promises 187
Comparison with Callbacks 191
The catch Method 192
The finally Method 194
throw in then, catch, and finally Handlers 198
The then Method with Two Arguments 199
Adding Handlers to Already Settled Promises 201
Creating Promises 202
The Promise Constructor 203
Promise.resolve 205
Promise.reject 206
Other Promise Utility Methods 207
Promise.all 207
Promise.race 209
Promise.allSettled 209
Promise.any 210

xxi
Contents

Promise Patterns 210


Handle Errors or Return the Promise 210
Promises in Series 211
Promises in Parallel 213
Promise Anti-Patterns 214
Unnecessary new Promise(/*...*/) 214
Not Handling Errors (or Not Properly) 214
Letting Errors Go Unnoticed When Converting a Callback API 214
Implicitly Converting Rejection to Fulfillment 215
Trying to Use Results Outside the Chain 216
Using Do-Nothing Handlers 216
Branching the Chain Incorrectly 217
Promise Subclasses 218
Old Habits to New 219
Use Promises Instead of Success/Failure Callbacks 219

CHAPTER 9: ASYNCHRONOUS FUNCTIONS, ITERATORS, AND


GENERATORS 221

async Functions 222


async Functions Create Promises 224
await Consumes Promises 225
Standard Logic Is Asynchronous When await Is Used 225
Rejections Are Exceptions, Exceptions Are Rejections; Fulfillments
Are Results, Returns Are Resolutions 227
Parallel Operations in async Functions 229
You Don’t Need return await 230
Pitfall: Using an async Function in an Unexpected Place 231
async Iterators, Iterables, and Generators 232
Asynchronous Iterators 233
Asynchronous Generators 236
for-await-of 238
Old Habits to New 238
Use async Functions and await Instead of Explicit
Promises and then/catch 238

CHAPTER 10: TEMPLATES, TAG FUNCTIONS, AND NEW STRING


FEATURES 241

Template Literals 241


Basic Functionality (Untagged Template Literals) 242
Template Tag Functions (Tagged Template Literals) 243
String.raw 248

xxii
Contents

Reusing Template Literals 249


Template Literals and Automatic Semicolon Insertion 250
Improved Unicode Support 250
Unicode, and What Is a JavaScript String? 250
Code Point Escape Sequence 252
String.fromCodePoint 252
String.prototype.codePointAt 252
String.prototype.normalize 253
Iteration 255
New String Methods 256
String.prototype.repeat 256
String.prototype.startsWith, endsWith 256
String.prototype.includes 257
String.prototype.padStart, padEnd 257
String.prototype.trimStart, trimEnd 258
Updates to the match, split, search, and replace Methods 259
Old Habits to New 260
Use Template Literals Instead of String Concatenation
(Where Appropriate) 260
Use Tag Functions and Template Literals for DSLs Instead
of Custom Placeholder Mechanisms 261
Use String Iterators 261

CHAPTER 11: NEW ARRAY FEATURES, TYPED ARRAYS 263

New Array Methods 264


Array.of 264
Array.from 264
Array.prototype.keys 266
Array.prototype.values 267
Array.prototype.entries 268
Array.prototype.copyWithin 269
Array.prototype.find 271
Array.prototype.findIndex 273
Array.prototype.fill 273
Common Pitfall: Using an Object As the Fill Value 273
Array.prototype.includes 274
Array.prototype.flat 275
Array.prototype.flatMap 276
Iteration, Spread, Destructuring 276
Stable Array Sort 276

xxiii
Contents

Typed Arrays 277


Overview 277
Basic Use 279
Value Conversion Details 280
ArrayBuffer: The Storage Used by Typed Arrays 282
Endianness (Byte Order) 284
DataView: Raw Access to the Buffer 286
Sharing an ArrayBuffer Between Arrays 287
Sharing Without Overlap 287
Sharing with Overlap 288
Subclassing Typed Arrays 289
Typed Array Methods 289
Standard Array Methods 289
%TypedArray%.prototype.set 290
%TypedArray%.prototype.subarray 291
Old Habits to New 292
Use find and findIndex to Search Arrays Instead of
Loops (Where Appropriate) 292
Use Array.fill to Fill Arrays Rather Than Loops 292
Use readAsArrayBuffer Instead of readAsBinaryString 292

CHAPTER 12: MAPS AND SETS 293

Maps 293
Basic Map Operations 294
Key Equality 296
Creating Maps from Iterables 297
Iterating the Map Contents 297
Subclassing Map 299
Performance 300
Sets 300
Basic Set Operations 301
Creating Sets from Iterables 302
Iterating the Set Contents 302
Subclassing Set 303
Performance 304
WeakMaps 304
WeakMaps Are Not Iterable 305
Use Cases and Examples 305
Use Case: Private Information 305
Use Case: Storing Information for Objects Outside Your Control 307
Values Referring Back to the Key 308

xxiv
Contents

WeakSets 314
Use Case: Tracking 314
Use Case: Branding 315
Old Habits to New 316
Use Maps Instead of Objects for General-Purpose Maps 316
Use Sets Instead of Objects for Sets 316
Use WeakMaps for Storing Private Data Instead of Public Properties 317

CHAPTER 13: MODULES 319

Introduction to Modules 319


Module Fundamentals 320
The Module Specifier 322
Basic Named Exports 322
Default Export 324
Using Modules in Browsers 325
Module Scripts Don’t Delay Parsing 326
The nomodule Attribute 327
Module Specifiers on the Web 328
Using Modules in Node.js 328
Module Specifiers in Node.js 330
Node.js is Adding More Module Features 331
Renaming Exports 331
Re-Exporting Exports from Another Module 332
Renaming Imports 333
Importing a Module’s Namespace Object 333
Exporting Another Module’s Namespace Object 334
Importing a Module Just for Side Effects 335
Import and Export Entries 335
Import Entries 335
Export Entries 336
Imports Are Live and Read-Only 338
Module Instances Are Realm-Specific 340
How Modules Are Loaded 341
Fetching and Parsing 342
Instantiation 344
Evaluation 346
Temporal Dead Zone (TDZ) Review 346
Cyclic Dependencies and the TDZ 347
Import/Export Syntax Review 348
Export Varieties 348
Import Varieties 350

xxv
Contents

Dynamic Import 350


Importing a Module Dynamically 351
Dynamic Module Example 352
Dynamic Import in Non-Module Scripts 356
Tree Shaking 357
Bundling 359
Import Metadata 360
Worker Modules 360
Loading a Web Worker as a Module 360
Loading a Node.js Worker as a Module 361
A Worker Is in Its Own Realm 361
Old Habits to New 362
Use Modules Instead of Pseudo-Namespaces 362
Use Modules Instead of Wrapping Code in Scoping Functions 363
Use Modules to Avoid Creating Megalithic Code Files 363
Convert CJS, AMD, and Other Modules to ESM 363
Use a Well-Maintained Bundler Rather Than Going Homebrew 363

CHAPTER 14: REFLECTION—REFLECT AND PROXY 365

Reflect 365
Reflect.apply 367
Reflect.construct 367
Reflect.ownKeys 368
Reflect.get, Reflect.set 369
Other Reflect Functions 370
Proxy 371
Example: Logging Proxy 373
Proxy Traps 381
Common Features 381
The apply Trap 381
The construct Trap 382
The defineProperty Trap 382
The deleteProperty Trap 384
The get Trap 385
The getOwnPropertyDescriptor Trap 386
The getPrototypeOf Trap 387
The has Trap 388
The isExtensible Trap 388
The ownKeys Trap 388

xxvi
Contents

The preventExtensions Trap 389


The set Trap 389
The setPrototypeOf Trap 390
Example: Hiding Properties 391
Revocable Proxies 394
Old Habits to New 395
Use Proxies Rather Than Relying on Consumer Code
Not to Modify API Objects 395
Use Proxies to Separate Implementation Code from
Instrumenting Code 395

CHAPTER 15: REGULAR EXPRESSION UPDATES 397

The Flags Property 398


New Flags 398
The Sticky Flag (y) 398
The Unicode Flag (u) 399
The “Dot All” Flag (s) 400
Named Capture Groups 400
Basic Functionality 400
Backreferences 404
Replacement Tokens 405
Lookbehind Assertions 405
Positive Lookbehind 405
Negative Lookbehind 406
Greediness Is Right-to-Left in Lookbehinds 407
Capture Group Numbering and References 407
Unicode Features 408
Code Point Escapes 408
Unicode Property Escapes 409
Old Habits to New 413
Use the Sticky Flag (y) Instead of Creating Substrings and
Using ^ When Parsing 413
Use the Dot All Flag (s) Instead of Using Workarounds to
Match All Characters (Including Line Breaks) 414
Use Named Capture Groups Instead of Anonymous Ones 414
Use Lookbehinds Instead of Various Workarounds 415
Use Code Point Escapes Instead of Surrogate Pairs in
Regular Expressions 415
Use Unicode Patterns Instead of Workarounds 415

xxvii
Another random document with
no related content on Scribd:
The bony plate ends just above the root of the nose.
The dissection is now carried on downward until the bones proper
of the nose appear, and latterly, so that the saw does not injure the
soft parts, and to act as a guide for the course of the latter.
The position of the flap and the saw in position is shown in Fig.
409.

Fig. 408.—First step.


Fig. 409.—Making lower nasal flap section.
Nélaton Method.
The saw is made to sever the nasal bones from the apophyses of
the superior maxillary. The blade follows a line starting one
centimeter anterior to the anterior and superior nasal spine, and is
directed downward toward the second molar, not going entirely
through the apophyses.
The latter are broken with the chisel in such way that some of the
bony border lies in contact with the nasal process of the superior
maxillary.
This fracturing is made as the flap is still further brought down, as
in Fig. 410.
The flap is now so adjusted that its median bone-lined section will
form the median third of the nose, the base being made by folding
the flap upon itself, as shown in Fig. 411.

Fig. 410.—Forming base of nose.


Fig. 411.—Ultimate disposition of entire flap.
Nélaton Method.

The raw surfaces are sutured at their point of coaptation, laterally,


and to the margins of the genian flaps.
The frontal wound is brought together by suture as closely as
possible, and Thiersch grafts are employed to close any wound still
remaining.
The objections to this operation is that of all bone-plate flaps. A
flap containing a cartilaginous support taken from the eighth costal
cartilage, as previously described, would undoubtedly give the best
results.

Restoration of Lobule and Alæ

The defect being at a distance from the forehead, the employment


of frontal flaps for the restoration of the lobule and alæ are to be
eliminated; furthermore, such methods would involve the incision
and dissection of the healthy skin of the nose to no advantage but
disfigurement, and possible further loss of the organ.
The results with autoplasties about this part of the nose are
usually excellent, and particularly gratifying are those obtained with
the Italian method, in which the flap is made from the skin of the
forearm.
French methods involving large nasogenian flaps are not to be
used because of their consequent retraction and cicatrization of the
cheeks. Small lining nasogenian flaps may be utilized where
necessary, since they cause little scarring.
If the loss of tissue is very small, the flaps to reform the parts may
be taken from the nasal skin and the septum be made of a flap from
the upper lip. Both such secondary wounds could be drawn together
by suture, leaving slight linear scars. Operations of this nature will
be described separately later. Some of the methods referred to might
be combined for small defects of this nature.
Defects of larger extent may be corrected as follows:
Küster Method.—A flap of considerable size is outlined on the
skin of the arm and cut laterally, leaving it attached at both ends in
bridge fashion.
Gauze dressings are inserted under the flap. Several days later the
superior pedicle is severed and the flap is sutured to the freshened
margin of the nose. An application of borated vaselin on gauze is
used as the dressing. The arm is held in position by a proper
apparatus, a plaster-of-Paris fixture being used by the author.
Six days later the brachial plexus is divided to half its width, and
totally divided three days thereafter.
Fifteen days later the free border of the flap is divided into three
sections, the median one being made narrowest. The outer small
flaps thus made are sutured to the remaining wings of the nose.
Five days later the septum is formed of the remaining unattached
flap, which is sutured to the stump of the old septum. It is not
folded upon itself, but allowed to heal by cicatrization.
Eight days later minor operations are performed to reduce the
exuberant portions of the side flaps.
Berger Method.—This author makes a flap of the skin above the
border of the nose, which he turns down, raw surface outward, upon
which he immediately brings a flap from the arm. The object of the
lining is to give stability to the base of the new nose as well as to
prevent curling and contraction of the rims of the nostrils.
Bayer-Payr Method.—Two flaps two and a half centimeters wide
are cut from the nasolabial furrow, extending down to the lower
border of the inferior maxillary bone, as shown in Fig. 412.
The flaps are dissected up and brought forward and upward, their
raw surfaces meeting in the median line, where they are sutured
upon one another to the extent of three centimeters, as shown in
Fig. 413.
The nasolabial wounds are brought together by suture except for
a small triangular space near each pedicle, which are allowed to heal
by granulation.
The superior borders of the flaps were then united by suture to
the freshened margins of the nose, which have been prepared as
shown in the illustration.
The septal ends of the two flaps are likewise sutured to the stump
of the old septum.
The raw or outer surfaces of the flaps are to be covered with
Thiersch grafts when ready for them, though this may not be
necessary with small flaps.
The pedicles of the flaps are not cut until the end of the fourth
week, when the fresh ends may be sutured to freshened surfaces of
the wings made to receive them.
The disposition of the parts at this period is shown in Fig. 414.
Fig. 412.—First step.
Fig. 413.—Disposition of flaps.
Fig. 414.—Ultimate placing of pedicles after division.
Bayer-Payr Method.

Ch. Nélaton Method.—This author in cases of extensive


destruction of the point of the nose advocates the lining of an Italian
flap with skin flaps made in similar manner, as in the foregoing
operation.
The lining flaps are taken from the nasogenian furrow, placed and
sutured as just described, without twisting of their pedicles, and are
sutured at the median line and at their free ends to the freshened
septal stumps.
The Italian flap is placed over those two flaps immediately, or the
Italian flap is first made to unite to the raw margin of the defect,
and the two nasogenian flaps are made and employed at a later
sitting by subplanting.
The Italian flap may be taken from the arm or forearm, this
surgeon preferring the forearm. The attached flap and position of
the hand on the forehead where it is retained with an apparatus for
the required time is shown in Fig. 415.
The adherent Italian flap and its subseptal addition and the
outlines for the lining flaps are shown in Fig. 416.
The secondary nasogenian wounds reduced by suture and the
flaps so obtained are shown in Fig. 417. The subseptal section of the
Italian flap is raised to show the disposition of the flap ends to form
the new septum. The raised flap is brought down and sutured to the
raw edges of the two septal flaps covering the median cicatrix, its
own cicatrices falling within the rim of the nostrils.
Fig. 415.—Attachment of flap from forearm.
Fig. 416.—Forearm flap in position and outline of lateral flaps.
Fig. 417.—Disposition of lateral flaps.
Ch. Nélaton Method.
This surgeon advises in less severe losses of tissue to do without
lining the Italian flap, but to make the latter large enough to be able
to fold in enough of its base sections to line the nostrils to the extent
of the inferior line of the mucosa. The flap should be cut one fourth
longer than the nasal deformity.
This procedure also overcomes to a great extent the shrinking of
the nasal orifices.
The pedicle of the flap is cut close to the arm at the end of two
weeks. The subseptum may be made at once if the flap shows good
nutrition, as evidenced by marked bleeding at the time of cutting
away the bridge tissue.

Restoration of the Alæ

The method of restoration of the wing or wings of the nose


depends largely upon the extent of the tissue loss.
The use of the Hindu method is not advisable, since the flap must
be made with a long pedicle, which involves the making of a large
wound and predisposes to consequent large cicatrices, although
many surgeons have resorted to the method. The author does not
see any advantage with this method, even if the loss of tissue about
the lobule is great.
The best results, both as to the primary and secondary wounds,
are those obtained with the Italian method, and in extensive cases
the use of a combined flap, wherein the lining flap is taken from the
nasolabial furrow or just above it. This leaves a linear scar that does
not disfigure the face, and assures of better contour than when a
single integumentary flap is employed which, as has been so
frequently mentioned, is liable to curl inward and contract in an
upward direction, adding little to the area of lost tissue.
The ideal operations are those which include cartilaginous
supports, which may be obtained from about the border of the
deformity or from some remote place, as of the ear. The surgeon is
hardly justified to use the remaining healthy tissue of the nose,
unless the case is such that the secondary wound can be corrected,
so as not to add scars to the face.
Small defects can be easily corrected by sliding flaps taken from
the vicinity of the defect, whether they include cartilage or not, and
by granulation or dissection and approximation of the skin, the
secondary wound may be entirely closed. It is remarkable how little
linear scars show about the nose when the lips of the wounds have
been neatly brought together.
The author advocates the use of the continuous silk suture for this
purpose, since it fulfills both the object of suture and splint and
overcomes the corrugating effect, so often found with interrupted
sutures; furthermore, a continuous suture is more easily withdrawn,
and there is no danger of wounding the skin on removal, and the
discomfort to the patient is greatly reduced.
From the foregoing descriptions of procedure, the surgeon has
been sufficiently familiarized with such steps in rhinoplasty as are
usually employed, and it would be a matter of constant repetition to
rehearse these same steps for the following operations; therefore
the author trusts the illustrations given will be sufficiently lucid to
work from. All special features to be observed are given.
Denonvillier Method.—The secondary wounds made by the two
methods here given may be allowed to heal by granulation or be
covered with skin grafts, as heretofore described.
Fig. 418.—Making of flap. Pedicle anterior.
Fig. 419.—Disposition of flap.
Fig. 420.—Pedicle posterior.
Fig. 421.—Disposition of flap.
Denonvillier Method.
Mutter Method.—A skin flap is taken from the cheek and slid
forward into the defect as shown.

Fig. 422. Fig. 423.


Mutter Method.

Von Langenbeck Method.—The skin flap is taken from the


healthy side of the nose and brought into the defect by sliding.
The secondary wound is allowed to heal by granulation.
Fig. 424. Fig. 425.
Von Langenbeck Method.

Busch Method.—The same method as above is employed except


that for the incision A, C, which, upon dissection of the skin in
triangle A, B, C, allows the closure of a larger defect than could be
corrected with the lateral nasal flap alone (see Fig. 426).

Fig. 426.—Busch Method.

The following illustrations are similar to those given and involve


only the skin in the flaps made, as shown. They are only of interest
in portraying the position of the flaps and their pedicles.
Fig. 427.—Dieffenbach Method.
Fig. 428.—Dupuytren Method.
Fig. 429.—Fritz-Reich Method.
Fig. 430. Fig. 431. Fig. 432. Fig. 433.
Sedillot Method.
Fig. 434. Fig. 435.
Nélaton Method.

In the Bonnet method the flap is taken from the entire thickness
of the upper lip and by twisting is brought into the defect. The
pedicle must be cut at a later sitting.
Fig. 436. Fig. 437.
Bonnet Method.

Weber Method.—The flap is made from half the thickness of the


upper lip, as shown in Fig. 438, and brought into the defect, as in
Fig. 439. The pedicle is cut later.
Fig. 438. Fig. 439.
Weber Method.

Thompson Method.—This author uses a lateral flap taken from


the cheek, as shown in Fig. 441, and lines it with a flap of mucosa
dissected from the septum antero-posteriorly, as shown in Fig. 440,
disposing of the latter flap as shown. The raw surface meets the raw
surface of the skin flap, as in Fig. 442.
At a later sitting the two pedicles must be severed and adjusted
by small minor operations.

Fig. 440.—Mucosa flap.


Fig. 441. Fig. 442.
Thompson Method.

Blandin Method.—The flap is made of the whole thickness of the


lip. The pedicle is cut at a second sitting.
Fig. 443. Fig. 444.
Blandin Method.

Von Hacker Method.—This author adds a flap from the


nasolabial region to line that taken from the healthy side of the
nose, as shown in the Langenbeck method. There is little
cicatrization here, and the result is excellent for defects of large
area.
The procedure and shape of flaps as used are shown in Figs. 445
and 446.
Fig. 445. Fig. 446.
Von Hacker Method.

Kolle Method.—The author dissects away the flap E, A, D when


part of the mucosa and cartilaginous tissue remains, and where
there is a loss, total or partial, of the alar rima, the transverse
incision E being made as long as required to overcome the defect by
sliding, as in Fig. 447.
The latter flap is freshened at its inferior border along the line D,
and a second or bordering flap of sufficient width to line and face
the nostril is taken up from the upper lip, skin only, as shown in area
C.
The lateral or upper flap is now slid down to slightly overcome the
loss of tissue and the flap C is brought upward by twisting slightly on
its pedicle and sutured in place, as shown in Fig. 448.
The secondary wound lying between the lines E and E’,
occasioned by the sliding downward and leaving the triangular
defect F, is allowed to heal by granulation. The lateral flap is fixed
along the line A.
Usually the pedicle of flap C need not be cut, as it adjusts itself
under primary union.
The secondary lip wound is closed at once by suture. The author
has also used the inverted V incision of Dieffenbach, including the
cartilage or part thereof that remains above the defect, and has
moved this flap downward, suturing in Y fashion with good results.

Fig. 447. Fig. 448.


Author’s Method.

Denonvillier Method.—The operation is similar to that of


Dieffenbach and the author’s modification just mentioned. Its
advantage, as in the latter, is that the inferior border or nasal rim
remains intact, and contains what cartilage remains above the
defect. The shape of the incision is as shown in Fig. 449.
The flap A, B, C includes the skin and such cartilage as can be
used, while the rim below the line B, D retains its lower cicatricial
border.
The flap is slid down until the defect has been overcome, and the
resultant superior triangular wound is allowed to heal by granulation.
The dissection of the flap is made down to the line including the skin
or cartilage referred to. At the dotted line B, D the whole thickness
of the tissue except the overlying skin is involved.
Fig. 449.—Denonvillier Method.

Von Hacker Method.—The flap A, F, C, as shown in Fig. 450, is


cut from the entire thickness of the side of the nose attached by its
posterior pedicle C.
This flap is moved downward, and its anterior border is sutured
along the freshened line A, B, as in Fig. 451, leaving a triangular
defect, A, F, C.
Two little triangular flaps of skin are dissected up, skin only, at D,
E, C and H, G, C.
Next a rectangular flap, I, K, L, M, is dissected up from the cheek,
as in Fig. 452, including some areolar tissue.
The flap should be made sufficiently long, so that when folded
over it will fit into the defect without tension, at the same time
allowing for contraction.
This flap is sutured into the defect made by the making of the first
flap, as shown.
The secondary wound of the cheek is brought together by suture,
except for a small triangle near the pedicle to avoid its constriction.
Its raw surface is allowed to heal by granulation. The pedicle is
severed in about fifteen days, and may be cut in triangular fashion
to make it fit smoothly into the slight defect in the skin just posterior
to it.

Fig. 450. Fig. 451. Fig. 452.


Von Hacker Method.
König Method.—In this novel method a flap somewhat of the
form of the defect is taken from about the entire thickness of the rim
of the ear, as shown in Fig. 453.
This flap should be made slightly larger than the defect, since it
contracts somewhat immediately after excision.
It is sutured rim down to the freshened wound in the wing.
The secondary deformity of the ear is brought together by suture.
The author has found that this cannot be readily done without
puckering the rim when the line of excision is made convexly, and
advises making it triangular instead. The defect of the nose should
be freshened to the same form. The flap from the ear now becomes
ideal, fits better, is more readily sutured in place. No sutures should,
however, be made through the apex of this triangular flap to avoid
gangrene at this frail point. Silk isinglass at this point acts as a splint.
Dry aristol dressings are used.

Fig. 453.—König Method.


Kolle Method.—When the defect of the ala is elongated and
involves only part of the rim, the author has taken a cutaneo-
cartilaginous flap from the back of the ear.
The flap is cut vertically, and is made to include a strip of cartilage
of about the size and form of the defect.
The flap is immediately sutured to the freshened defect and folded
upon itself with the cartilage facing the inferior margin of the defect.
The flap thus employed exhibits an epidermal face, both inside
and outside as well as at the rim of the wing.
A case in which this method was used is shown in the illustrations
454 and 455, in which the defect is shown in the former figure, and
the result after the sutures were withdrawn on the sixth day in the
latter.
The secondary wound is easily brought together by suture, as the
skin is quite flexible at this point.

Fig. 454. Fig. 455.


Author’s Case.

Restoration of Nasal Lobule

This defect of the nose has been restored by the use of skin flaps
taken from the forehead, the nose itself, or from half or the whole
thickness of the upper lip. The author does not advocate the use of
such flaps except those taken from the skin of the inner side of the
forearm, just below the wrist, made according to the Italian plan, as
heretofore described.
The pedicle of such a flap is cut about the twelfth day, and at a
later period, when the inferior or free margin has cicatrized, the
subseptum is formed and sutured to the remaining stump or into a
wound in the upper lip made to receive it.
The skin of the forearm is nearer to the thickness of the skin of
the nose; hence a flap from it is preferable to that taken from the
arm.
The method of obtaining the flap has been fully described
heretofore.
The results obtained are excellent in most cases. The resulting
cicatrix is barely visible, and may be later improved by scar-reducing
methods, later described under that heading.
The appearance of the flap after the pedicle has been severed and
the subseptal section has been put into place may be observed in
Fig. 456, and the final appearance after total contraction, in Fig. 457.
Fig. 456.—Flap detached.
Fig. 457.—Final appearance.
Author’s Case.

For very small losses of tissue about the lobule nonpedunculated


skin grafts are to be employed. The author advises including some of
the areolar tissue with them to avoid contraction.
These are to be dressed with the blood method referred to under
skin grafting. Perforated rubber tissue is to be used next to the
epidermal surface to prevent the dressings from tearing away the
graft when changed.
Fine twisted silk is most suitable for suturing purposes. The loops
must not be drawn too tightly and the knot be made so that it rests
upon the healthy skin of the nose.

Restoration of Subseptum

You might also like