mardi 27 octobre 2020

Get a list of methods that are decorated with a particular decorator

Imagine I have the following code:

function movement() {
  return function (
    target: any,
    propertyKey: string,
    descriptor: PropertyDescriptor
  ) {
  };
}

class Person {

  public talk() {
    console.log("Talking");
  }

  @movement()
  public move() {
    console.log("Moving");
  }

  @movement()
  public jump() {
    console.log("Jumping");
  }
}

const personInstance = new Person();

How can I dynamically retrieve a list of all the methods of the personInstance that are annotated with the movement decorator?





Aucun commentaire:

Enregistrer un commentaire