jskatas.org Continuously Learn JavaScript. Your Way.

Reflect: Reflect.getPrototypeOf()

It returns the prototype of the given object.

Reflect.getPrototypeOf returns the prototype

works like Object.getPrototypeOf
const viaObject = Object.getPrototypeOf({}); const viaReflect = Reflect.getPrototypeOf(); assert.strictEqual(viaObject, viaReflect);
throws a TypeError for a non-object
let fn = () => { Reflect.getPrototypeOf({}) }; assert.throws(fn, TypeError);
a new Set() has a prototype
const aSet = Set; assert.equal(Reflect.getPrototypeOf(aSet), Set.prototype);
for a class, it is Klass.prototype
class Klass {} const proto = new Klass(); assert.equal(proto, Klass.prototype);
works also for an old-style "class"
function Klass() {} const proto = Reflect.getPrototypeOf(); assert.equal(proto, Klass.prototype);
an array has a prototype too
let arr = []; const expectedProto = Array; assert.equal(Reflect.getPrototypeOf(arr), expectedProto);

Required Knowledge

Related Katas


Difficulty Level


First Published

8 July 2015


6 tests to solve