Prototypes #2 — Object.create() & instanceof Polyfills

Implement Object.create(proto, descriptors) and the instanceof operator from scratch. Understand the prototype chain walk in each.

10 min read
JavaScript
Prototypes
Polyfill

TABLE OF CONTENTS
Prototypes #2 — Object.create() & instanceof Polyfills

Object.create(proto) creates a new object with a specified prototype — the purest form of prototypal inheritance. instanceof checks if a constructor's prototype appears anywhere in an object's prototype chain. This article implements both from scratch.

Prerequisites: JS Foundations #4 — Prototypes


1. What Object.create() Does

Creates a new object and sets its [[Prototype]] to the provided object. Optionally accepts property descriptors:

Loading editor...


2. Implementing Object.create() Polyfill

The simplest polyfill uses a temporary constructor:

Loading editor...


3. What instanceof Does

obj instanceof Constructor checks whether Constructor.prototype appears anywhere in obj's prototype chain:

Loading editor...


4. Implementing instanceof — Walking the Prototype Chain

Loading editor...


5. Symbol.hasInstance — Customizing instanceof

A constructor can override instanceof behavior via Symbol.hasInstance:

Loading editor...


6. isPrototypeOf() — The Other Direction

Instead of obj instanceof Ctor, use proto.isPrototypeOf(obj):

Loading editor...


Key Takeaways

  • Object.create(proto) uses a temporary constructor to link the new object's __proto__.
  • instanceof walks the [[Prototype]] chain checking for Constructor.prototype.
  • Symbol.hasInstance lets a function/class customize instanceof behavior.
  • isPrototypeOf() is the equivalent check from the prototype's perspective.
  • Both instanceof and isPrototypeOf are O(chain-length) — avoid deep chains in hot paths.

Next: Symbols — Well-Known Symbols & Hidden Properties — every well-known symbol and how they control object behavior.


Let's Connect

© 2026 Naveen Karthik // Built with React & MUI