chapter two

2 Prototype-centric object modeling

 

This chapter covers

  • Three prototype-centered object models: prototypal inheritance, constructor functions, and classes
  • A review of JavaScript’s property resolution mechanism
  • The “prototypal inheritance” oxymoron
  • Advantages and drawbacks of classes in JavaScript

“Merely adding "prototypal" in front to distinguish the actually nearly opposite behavior in JavaScript has left in its wake nearly two decades of miry confusion”

Kyle Simpson

Objects are the fabric of JavaScript. Yet for something that we deal with routinely, they still continue to be the most intimidating part about the language. The most common question that I hear is: How do I properly model inheritance? Every article or book you read does it in slightly different ways and for some reason even the experienced developer needs to turn to a search engine to relearn it once in a while.

2.1   Reviewing “prototypal inheritance”

2.1.1   Property resolution process

2.1.2   Differential inheritance

2.2   Constructor functions

2.2.1   Abstracting object creation

2.2.2   The “new” gotchas

2.3   Class-based inheritance

2.3.1   Prototype inheritance !== class inheritance

2.3.2   Limitations of JavaScript’s class system

2.4   Summary