Cover image for You Don't Know JS: this & Object Prototypes

Book Description

No matter how much experience you have with JavaScript, odds are you don’t fully understand the language. This concise, in-depth guide takes you inside JavaScript’s this structure and object prototypes. You’ll learn how they work and why they’re integral to behavior delegation—a design pattern in which objects are linked, rather than cloned. Like other books in the "You Don’t Know JS" series, this and Object Prototypes dives into trickier parts of the language that many JavaScript programmers simply avoid.

Table of Contents

  1. Foreword
  2. Preface
    1. Mission
    2. Review
    3. Conventions Used in This Book
    4. Using Code Examples
    5. Safari® Books Online
    6. How to Contact Us
  3. 1. this or That?
    1. Why this?
    2. Confusions
      1. Itself
      2. Its Scope
    3. What’s this?
    4. Review
  4. 2. this All Makes Sense Now!
    1. Call-Site
    2. Nothing but Rules
      1. Default Binding
      2. Implicit Binding
        1. Implicitly lost
      3. Explicit Binding
        1. Hard binding
        2. API call “contexts”
      4. new Binding
    3. Everything in Order
      1. Determining this
    4. Binding Exceptions
      1. Ignored this
        1. Safer this
      2. Indirection
      3. Softening Binding
    5. Lexical this
    6. Review
  5. 3. Objects
    1. Syntax
    2. Type
      1. Built-in Objects
    3. Contents
      1. Computed Property Names
      2. Property Versus Method
      3. Arrays
      4. Duplicating Objects
      5. Property Descriptors
        1. Writable
        2. Configurable
        3. Enumerable
      6. Immutability
        1. Object constant
        2. Prevent extensions
        3. Seal
        4. Freeze
      7. [[Get]]
      8. [[Put]]
      9. Getters and Setters
      10. Existence
        1. Enumeration
    4. Iteration
    5. Review
  6. 4. Mixing (Up) “Class” Objects
    1. Class Theory
      1. “Class” Design Pattern
      2. JavaScript “Classes”
    2. Class Mechanics
      1. Building
      2. Constructor
    3. Class Inheritance
      1. Polymorphism
      2. Multiple Inheritance
    4. Mixins
      1. Explicit Mixins
        1. Polymorphism revisited
        2. Mixing copies
        3. Parasitic inheritance
      2. Implicit Mixins
    5. Review
  7. 5. Prototypes
    1. [[Prototype]]
      1. Object.prototype
      2. Setting and Shadowing Properties
    2. “Class”
      1. “Class” Functions
        1. What’s in a name?
      2. “Constructors”
        1. Constructor or call?
      3. Mechanics
        1. “Constructor” redux
    3. (Prototypal) Inheritance
      1. Inspecting “Class” Relationships
    4. Object Links
      1. Create()ing Links
        1. Object.create() polyfill
      2. Links as Fallbacks?
    5. Review
  8. 6. Behavior Delegation
    1. Toward Delegation-Oriented Design
      1. Class Theory
      2. Delegation Theory
        1. Mutual delegation (disallowed)
        2. Debugged
      3. Mental Models Compared
    2. Classes Versus Objects
      1. Widget “Classes”
        1. ES6 class sugar
      2. Delegating Widget Objects
    3. Simpler Design
      1. De-class-ified
    4. Nicer Syntax
      1. Unlexical
    5. Introspection
    6. Review
  9. A. ES6 Class
    1. class
    2. class Gotchas
    3. Static > Dynamic?
    4. Review
  10. B. Acknowledgments
  11. Colophon
  12. Copyright