Page 31 - JavaScript
P. 31
Use a memoizer for heavy-computing functions 413
Benchmarking your code - measuring execution time 415
Prefer local variables to globals, attributes, and indexed values 417
Reuse objects rather than recreate 418
Example A 418
Example B 418
Limit DOM Updates 419
Initializing object properties with null 420
Be consistent in use of Numbers 421
Chapter 73: Promises 423
Syntax 423
Remarks 423
Examples 423
Promise chaining 423
Introduction 425
States and control flow 425
Example 425
Delay function call 426
Waiting for multiple concurrent promises 427
Waiting for the first of multiple concurrent promises 428
"Promisifying" values 428
"Promisifying" functions with callbacks 429
Error Handling 430
Chaining 430
Unhandled rejections 431
Caveats 432
Chaining with fulfill and reject 432
Synchronously throwing from function that should return a promise 433
Return a rejected promise with the error 433
Wrap your function into a promise chain 434
Reconciling synchronous and asynchronous operations 434
Reduce an array to chained promises 435

