Foreword |
|
xiii | |
Preface |
|
xv | |
Acknowledgments |
|
xvii | |
About the Author |
|
xix | |
|
Chapter 1 Accustoming Yourself to JavaScript |
|
|
1 | (30) |
|
Item 1 Know Which JavaScript You Are Using |
|
|
1 | (6) |
|
Item 2 Understand JavaScript's Floating-Point Numbers |
|
|
7 | (2) |
|
Item 3 Beware of Implicit Coercions |
|
|
9 | (6) |
|
Item 4 Prefer Primitives to Object Wrappers |
|
|
15 | (1) |
|
Item 5 Avoid using == with Mixed Types |
|
|
16 | (3) |
|
Item 6 Learn the Limits of Semicolon Insertion |
|
|
19 | (6) |
|
Item 7 Think of Strings As Sequences of 16-Bit Code Units |
|
|
25 | (6) |
|
|
31 | (26) |
|
Item 8 Minimize Use of the Global Object |
|
|
31 | (3) |
|
Item 9 Always Declare Local Variables |
|
|
34 | (1) |
|
|
35 | (4) |
|
Item 11 Get Comfortable with Closures |
|
|
39 | (3) |
|
Item 12 Understand Variable Hoisting |
|
|
42 | (2) |
|
Item 13 Use Immediately Invoked Function Expressions to Create Local Scopes |
|
|
44 | (3) |
|
Item 14 Beware of Unportable Scoping of Named Function Expressions |
|
|
47 | (3) |
|
Item 15 Beware of Unportable Scoping of Block-Local Function Declarations |
|
|
50 | (2) |
|
Item 16 Avoid Creating Local Variables with eval |
|
|
52 | (2) |
|
Item 17 Prefer Indirect eval to Direct eval |
|
|
54 | (3) |
|
Chapter 3 Working with Functions |
|
|
57 | (26) |
|
Item 18 Understand the Difference between Function, Method, and Constructor Calls |
|
|
57 | (3) |
|
Item 19 Get Comfortable Using Higher-Order Functions |
|
|
60 | (3) |
|
Item 20 Use call to Call Methods with a Custom Receiver |
|
|
63 | (2) |
|
Item 21 Use apply to Call Functions with Different Numbers of Arguments |
|
|
65 | (2) |
|
Item 22 Use arguments to Create Variadic Functions |
|
|
67 | (1) |
|
Item 23 Never Modify the arguments Object |
|
|
68 | (2) |
|
Item 24 Use a Variable to Save a Reference to arguments |
|
|
70 | (2) |
|
Item 25 Use bind to Extract Methods with a Fixed Receiver |
|
|
72 | (2) |
|
Item 26 Use bind to Curry Functions |
|
|
74 | (1) |
|
Item 27 Prefer Closures to Strings for Encapsulating Code |
|
|
75 | (2) |
|
Item 28 Avoid Relying on the to String Method of Functions |
|
|
77 | (2) |
|
Item 29 Avoid Nonstandard Stack Inspection Properties |
|
|
79 | (4) |
|
Chapter 4 Objects and Prototypes |
|
|
83 | (30) |
|
Item 30 Understand the Difference between prototype, getPrototypeOf, and_proto_ |
|
|
83 | (4) |
|
Item 31 Prefer Object.getPrototypeOf to _proto_ |
|
|
87 | (1) |
|
Item 32 Never Modify _proto_ |
|
|
88 | (1) |
|
Item 33 Make Your Constructors new-Agnostic |
|
|
89 | (3) |
|
Item 34 Store Methods on Prototypes |
|
|
92 | (2) |
|
Item 35 Use Closures to Store Private Data |
|
|
94 | (1) |
|
Item 36 Store Instance State Only on Instance Objects |
|
|
95 | (3) |
|
Item 37 Recognize the Implicit Binding of this |
|
|
98 | (3) |
|
Item 38 Call Superclass Constructors from Subclass Constructors |
|
|
101 | (4) |
|
Item 39 Never Reuse Superclass Property Names |
|
|
105 | (1) |
|
Item 40 Avoid Inheriting from Standard Classes |
|
|
106 | (3) |
|
Item 41 Treat Prototypes As an Implementation Detail |
|
|
109 | (1) |
|
Item 42 Avoid Reckless Monkey-Patching |
|
|
110 | (3) |
|
Chapter 5 Arrays and Dictionaries |
|
|
113 | (30) |
|
Item 43 Build Lightweight Dictionaries from Direct Instances of Object |
|
|
113 | (3) |
|
Item 44 Use null Prototypes to Prevent Prototype Pollution |
|
|
116 | (2) |
|
Item 45 Use hasOwnProperty to Protect Against Prototype Pollution |
|
|
118 | (5) |
|
Item 46 Prefer Arrays to Dictionaries for Ordered Collections |
|
|
123 | (2) |
|
Item 47 Never Add Enumerable Properties to Object.prototype |
|
|
125 | (2) |
|
Item 48 Avoid Modifying an Object during Enumeration |
|
|
127 | (5) |
|
Item 49 Prefer for Loops to for...in Loops for Array Iteration |
|
|
132 | (1) |
|
Item 50 Prefer Iteration Methods to Loops |
|
|
133 | (5) |
|
Item 51 Reuse Generic Array Methods on Array-Like Objects |
|
|
138 | (2) |
|
Item 52 Prefer Array Literals to the Array Constructor |
|
|
140 | (3) |
|
Chapter 6 Library and API Design |
|
|
143 | (28) |
|
Item 53 Maintain Consistent Conventions |
|
|
143 | (1) |
|
Item 54 Treat undefined As "No Value" |
|
|
144 | (5) |
|
Item 55 Accept Options Objects for Keyword Arguments |
|
|
149 | (4) |
|
Item 56 Avoid Unnecessary State |
|
|
153 | (3) |
|
Item 57 Use Structural Typing for Flexible Interfaces |
|
|
156 | (4) |
|
Item 58 Distinguish between Array and Array-Like |
|
|
160 | (4) |
|
Item 59 Avoid Excessive Coercion |
|
|
164 | (3) |
|
Item 60 Support Method Chaining |
|
|
167 | (4) |
|
|
171 | (30) |
|
Item 61 Don't Block the Event Queue on I/O |
|
|
172 | (3) |
|
Item 62 Use Nested or Named Callbacks for Asynchronous Sequencing |
|
|
175 | (4) |
|
Item 63 Be Aware of Dropped Errors |
|
|
179 | (4) |
|
Item 64 Use Recursion for Asynchronous Loops |
|
|
183 | (3) |
|
Item 65 Don't Block the Event Queue on Computation |
|
|
186 | (4) |
|
Item 66 Use a Counter to Perform Concurrent Operations |
|
|
190 | (4) |
|
Item 67 Never Call Asynchronous Callbacks Synchronously |
|
|
194 | (3) |
|
Item 68 Use Promises for Cleaner Asynchronous Logic |
|
|
197 | (4) |
Index |
|
201 | |