liveBook · Manning

What you will learn in Secrets of the JavaScript Ninja, Second Edition

by John Resig Bear Bibeault Josip Maras

Chapter by chapter

Chapter 1: Chapter 1. JavaScript is everywhere

The chapter introduction uses two developers’ experiences to show why JavaScript skills transfer across application domains and why the language has spread beyond web pages.

1.1 Understanding the JavaScript language · 1.1 Do you know? · 1.1.1 How will JavaScript evolve? · 1.1.2 Transpilers give us access to tomorrow’s JavaScript today · 1.2 Understanding the browser · 1.3 Using current best practices · 1.3.1 Debugging · 1.3.2 Testing · 1.3.3 Performance analysis · 1.4 Boosting skill transferability · 1.5 Summary

What you learn in chapter 1 →

Chapter 2: Chapter 2. Building the page at runtime

The introduction places JavaScript in the browser-based lifecycle of a client-side web application and identifies the basic roles of HTML, JavaScript, events, the DOM, and the event loop.

2.1 The lifecycle overview · 2.1 Do you know? · 2.2 The page-building phase · 2.2.1 Parsing the HTML and building the DOM · 2.2.2 Executing JavaScript code · 2.3 Event handling · 2.3.1 Event-handling overview · 2.3.2 Registering event handlers · 2.3.3 Handling events · 2.4 Summary · 2.5 Exercises

What you learn in chapter 2 →

Chapter 3: Chapter 3. First-class functions for the novice: definitions and arguments

The introduction explains why functions are central to JavaScript and establishes that they are first-class objects.

3.1 What’s with the functional difference? · 3.1 Do you know? · 3.1.1 Functions as first-class objects · 3.1.2 Callback functions · 3.2 Fun with functions as objects · 3.2.1 Storing functions · 3.2.2 Self-memoizing functions · 3.3 Defining functions · 3.3.1 Function declarations and function expressions · 3.3.2 Arrow functions · 3.4 Arguments and function parameters · 3.4.1 Rest parameters · 3.4.2 Default parameters · 3.5 Summary · 3.6 Exercises

What you learn in chapter 3 →

Chapter 4: Chapter 4. Functions for the journeyman: understanding function invocation

Introduces the implicit function parameters `this` and `arguments` and explains that how a function is invoked influences their values.

4.1 Using implicit function parameters · 4.1 Do you know? · 4.1.1 The arguments parameter · 4.1.2 The this parameter: introducing the function context · 4.2 Invoking functions · 4.2.1 Invocation as a function · 4.2.2 Invocation as a method · 4.2.3 Invocation as a constructor · 4.2.4 Invocation with the apply and call methods · 4.3 Fixing the problem of function contexts · 4.3.1 Using arrow functions to get around function contexts · 4.3.2 Using the bind method · 4.4 Summary · 4.5 Exercises

What you learn in chapter 4 →

Chapter 5: Chapter 5. Functions for the master: closures and scopes

The introduction explains why closures matter in JavaScript and links their existence to the way JavaScript scopes work.

5.1 Understanding closures · 5.1 Do you know? · 5.2 Putting closures to work · 5.2.1 Mimicking private variables · 5.2.2 Using closures with callbacks · 5.3 Tracking code execution with execution contexts · 5.4 Keeping track of identifiers with lexical environments · 5.4.1 Code nesting · 5.4.2 Code nesting and lexical environments · 5.5 Understanding types of JavaScript variables · 5.5.1 Variable mutability · 5.5.2 Variable definition keywords and lexical environments · 5.5.3 Registering identifiers within lexical environments · 5.6 Exploring how closures work · 5.6.1 Revisiting mimicking private variables with closures · 5.6.2 Private variables caveat · 5.6.3 Revisiting the closures and callbacks example · 5.7 Summary · 5.8 Exercises

What you learn in chapter 5 →

Chapter 6: Chapter 6. Functions for the future: generators and promises

Introduces generators and promises as ES6 features, explaining their basic roles before the chapter explores how to use them.

6.1 Making our async code elegant with generators and promises · 6.1 Do you know? · 6.2 Working with generator functions · 6.2.1 Controlling the generator through the iterator object · 6.2.2 Using generators · 6.2.3 Communicating with a generator · 6.2.4 Exploring generators under the hood · 6.3 Working with promises · 6.3.1 Understanding the problems with simple callbacks · 6.3.2 Diving into promises · 6.3.3 Rejecting promises · 6.3.4 Creating our first real-world promise · 6.3.5 Chaining promises · 6.3.6 Waiting for a number of promises · 6.4 Combining generators and promises · 6.4.1 Looking forward—the async function · 6.5 Summary · 6.6 Exercises

What you learn in chapter 6 →

Chapter 7: Chapter 7. Object orientation with prototypes

Introduces prototypes as the basis for JavaScript’s approach to object-oriented code.

7.1 Understanding prototypes · 7.1 Do you know? · 7.2 Object construction and prototypes · 7.2.1 Instance properties · 7.2.2 Side effects of the dynamic nature of JavaScript · 7.2.3 Object typing via constructors · 7.3 Achieving inheritance · 7.3.1 The problem of overriding the constructor property · 7.3.2 The instanceof operator · 7.4 Using JavaScript “classes” in ES6 · 7.4.1 Using the class keyword · 7.4.2 Implementing inheritance · 7.5 Summary · 7.6 Exercises

What you learn in chapter 7 →

Chapter 8: Chapter 8. Controlling access to objects

The introduction explains why changing JavaScript objects may need monitoring and identifies getters, setters, and proxies as ways to control access.

8.1 Controlling access to properties with getters and setters · 8.1 Do you know? · 8.1.1 Defining getters and setters · 8.1.2 Using getters and setters to validate property values · 8.1.3 Using getters and setters to define computed properties · 8.2 Using proxies to control access · 8.2.1 Using proxies for logging · 8.2.2 Using proxies for measuring performance · 8.2.3 Using proxies to autopopulate properties · 8.2.4 Using proxies to implement negative array indexes · 8.2.5 Performance costs of proxies · 8.3 Summary · 8.4 Exercises

What you learn in chapter 8 →

Chapter 9: Chapter 9. Dealing with collections

Introduces arrays, maps, and sets by identifying the basic role of each collection.

9.1 Arrays · 9.1 Do you know? · 9.1.1 Creating arrays · 9.1.2 Adding and removing items at either end of an array · 9.1.3 Adding and removing items at any array location · 9.1.4 Common operations on arrays · 9.1.5 Reusing built-in array functions · 9.2 Maps · 9.2.1 Don’t use objects as maps · 9.2.2 Creating our first map · 9.2.3 Iterating over maps · 9.3 Sets · 9.3.1 Creating our first set · 9.3.2 Union of sets · 9.3.3 Intersection of sets · 9.3.4 Difference of sets · 9.4 Summary · 9.5 Exercises

What you learn in chapter 9 →

Chapter 10: Chapter 10. Wrangling regular expressions

The chapter introduction explains why regular expressions are valuable for concise string processing in JavaScript and identifies common uses.

10.1 Why regular expressions rock · 10.1 Do you know? · 10.2 A regular expression refresher · 10.2.1 Regular expressions explained · 10.2.2 Terms and operators · 10.3 Compiling regular expressions · 10.4 Capturing matching segments · 10.4.1 Performing simple captures · 10.4.2 Matching using global expressions · 10.4.3 Referencing captures · 10.4.4 Noncapturing groups · 10.5 Replacing using functions · 10.6 Solving common problems with regular expressions · 10.6.1 Matching newlines · 10.6.2 Matching Unicode · 10.6.3 Matching escaped characters · 10.7 Summary · 10.8 Exercises

What you learn in chapter 10 →

Chapter 11: Chapter 11. Code modularization techniques

The introduction explains why growing JavaScript applications benefit from modules and why developers used modularization techniques before ES6 introduced native modules.

11.1 Modularizing code in pre-ES6 JavaScript · 11.1 Do you know? · 11.1.1 Using objects, closures, and immediate functions to specify modules · 11.1.2 Modularizing JavaScript applications with AMD and CommonJS · 11.2 ES6 modules · 11.2.1 Exporting and importing functionality · 11.3 Summary · 11.4 Exercises

What you learn in chapter 11 →

Chapter 12: Chapter 12. Working the DOM

The introduction explains why DOM modification matters for dynamic web applications and why understanding it can improve performance even when using a library.

12.1 Injecting HTML into the DOM · 12.1 Do you know? · 12.1.1 Converting HTML to DOM · 12.1.2 Inserting elements into the document · 12.2 Using DOM attributes and properties · 12.3 Styling attribute headaches · 12.3.1 Where are my styles? · 12.3.2 Style property naming · 12.3.3 Fetching computed styles · 12.3.4 Converting pixel values · 12.3.5 Measuring heights and widths · 12.4 Minimizing layout thrashing · 12.5 Summary · 12.6 Exercises

What you learn in chapter 12 →

Chapter 13: Chapter 13. Surviving events

The chapter introduction recalls a simplified event-loop model and defines timers as asynchronous delays before previewing the chapter’s topics.

13.1 Diving into the event loop · 13.1 Do you know? · 13.1.1 An example with only macrotasks · 13.1.2 An example with both macro- and microtasks · 13.2 Taming timers: time-outs and intervals · 13.2.1 Timer execution within the event loop · 13.2.2 Dealing with computationally expensive processing · 13.3 Working with events · 13.3.1 Propagating events through the DOM · 13.3.2 Custom events · 13.4 Summary · 13.5 Exercises

What you learn in chapter 13 →

Chapter 14: Chapter 14. Developing cross-browser strategies

The introduction frames cross-browser JavaScript development as a broad challenge that requires prioritizing limited project resources.

14.1 Cross-browser considerations · 14.1 Do you know? · 14.2 The five major development concerns · 14.2.1 Browser bugs and differences · 14.2.2 Browser bug fixes · 14.2.3 External code and markup · 14.2.4 Regressions · 14.3 Implementation strategies · 14.3.1 Safe cross-browser fixes · 14.3.2 Feature detection and polyfills · 14.3.3 Untestable browser issues · 14.4 Reducing assumptions · 14.5 Summary · 14.6 Exercises

What you learn in chapter 14 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.