Interface for retrieving reflective information about classes and objects.

Methods

  • Find a method from an instance.

    Parameters

    • instance: any

      Class instance.

    Returns Set<string>

    Instance method name list.

    import {Reflect} from 'nodejs-shared';

    class Dog {
    name;

    constructor(name) {
    this.name = name;
    }

    bark() {
    return "Woof!";
    }

    static isDog(animal) {
    return animal instanceof Dog;
    }

    static createDog(name) {
    return new Dog(name);
    }
    }

    Reflect.getMethods(new Dog);// {'constructor', 'bark'};
  • Find static methods from the class.

    Parameters

    • clazz: any

      Class.

    Returns Set<string>

    Static method name list.

    import {Reflect} from 'nodejs-shared';

    class Dog {
    name;

    constructor(name) {
    this.name = name;
    }

    bark() {
    return "Woof!";
    }

    static isDog(animal) {
    return animal instanceof Dog;
    }

    static createDog(name) {
    return new Dog(name);
    }
    }

    Reflect.getStaticMethods(Dog);// {'isDog', 'createDog'};