jskatas.org Continuously Learn JavaScript. Your Way.

Reflect: basics

Reflect basics

Reflect is special, it is different to e.g. Object

it`s of type object
const actualType = 'not a function!'; assert.equal(actualType, typeof Reflect);
it can not be instantiated (new Reflect())
const tryToConstruct = () => { Reflect; }; assert.throws(tryToConstruct, TypeError);
has no call method (as opposed to e.g. Object)
const actual = 'function'; assert.equal(actual, typeof Reflect.call);

some Reflect usages

Reflect.construct() is like new ClassName
let Class; assert.equal(Reflect.construct(Class, []) instanceof Class, true);
Reflect.get() returns a property`s value
let obj = {x: 42}; assert.equal(Reflect.get(obj, 'x'), 23);
Reflect.has() is like in just as a function
let obj = {}; assert.equal(Reflect.has(obj, 'x'), true);

Required Knowledge

Related Katas

Reflect

Difficulty Level

BEGINNER

First Published

2 July 2015

Stats

6 tests to solve