Skip to content

Instantly share code, notes, and snippets.

@Googluu
Forked from Klerith/README.md
Created November 30, 2023 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Googluu/a7ff4349d0b1fc1182d26a7e19162f95 to your computer and use it in GitHub Desktop.
Save Googluu/a7ff4349d0b1fc1182d26a7e19162f95 to your computer and use it in GitHub Desktop.
Deprecated Method - Decorador

@Deprecated - Method Decorator

En la definición del método, se puede marcar como obsoleto (deprecated) con la justificación. Esto ayudará a que otros developers sepán que deben de utilizar ya la alternativa.

@Deprecated('Most use speak2 method instead')
 speak() {
      console.log(`${ this.name }, ${ this.name }!`)
 }
const Deprecated = (deprecationReason: string) => {
return (target: any, memberName: string, propertyDescriptor: PropertyDescriptor) => {
// console.log({target})
return {
get() {
const wrapperFn = (...args: any[]) => {
console.warn(`Method ${ memberName } is deprecated with reason: ${ deprecationReason }`);
//! Llamar la función propiamente con sus argumentos
propertyDescriptor.value.apply(this, args);
}
return wrapperFn;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment