Created
August 8, 2024 17:13
-
-
Save faddah/fb990fee0b136694d531f1fe7c38a810 to your computer and use it in GitHub Desktop.
Example of creating a Decorator in TypeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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