JavaScript method for invoking interceptable JavaScript object internal methods

The Reflect namespace object contains static methods for invoking interceptable JavaScript object internal methods.

Some of the examples are provided below

Detecting whether an object contains certain properties

const duck = {
  name: "Maurice",
  color: "white",
  greeting() {
    console.log(`My name is ${this.name}`);
  },
};


Reflect.has(duck, "color");
// true
Reflect.has(duck, "haircut");
// false

Returning the object’s own keys

Reflect.ownKeys(duck);
// [ "name", "color", "greeting" ]

Leave a comment

Your email address will not be published. Required fields are marked *