Skip to content

Instantly share code, notes, and snippets.

@faddah
Created August 8, 2024 17:13
Show Gist options
  • Save faddah/fb990fee0b136694d531f1fe7c38a810 to your computer and use it in GitHub Desktop.
Save faddah/fb990fee0b136694d531f1fe7c38a810 to your computer and use it in GitHub Desktop.
Example of creating a Decorator in TypeScript
function Logger(logString: string) {
console.log('LOGGER FACTORY');
return function (constructor: Function) {
console.log(logString);
console.log(constructor);
};
}
@Logger(`LOGGING - PERSON...`)
class anotherPerson {
name: string = 'Faddah';
constructor() {
console.log('Creating person object...');
}
}
const person1 = new anotherPerson();
console.log(person1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment