Created
December 22, 2021 15:50
-
-
Save pshaddel/1a0161910462d91ee742ccfe0f25731c to your computer and use it in GitHub Desktop.
Simple Class Decorator That Logs on Console
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 firstClassDecorator(constructor: Function) { | |
console.log("first class decorator"); | |
} | |
@firstClassDecorator | |
class User { | |
public isActive: boolean; | |
public role: "admin" | "user"; | |
constructor() { | |
console.log("calling class constructor"); | |
this.isActive = true; | |
this.role = "user"; | |
} | |
} | |
const user = new User(); | |
console.log({ | |
isActive: user.isActive, | |
role: user.role, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment