How it works...

All JavaScript prototypes exist in a hierarchy. This means each prototype is extended from another, which in turn extends from another. At the top of the hierarchy is the null type. Object.getPrototypeOf traverses up this inheritance tree and climbs its way from the prototype of the instance, all the way to the null type. We can then use the name property of each, which will give us the name of that prototype (or class in our case).

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.