Last active
January 17, 2022 05:27
-
-
Save obaranovskyi/3c9114d171b3424fc5c906158b3c39ee to your computer and use it in GitHub Desktop.
This file contains 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 userCount() { | |
/* Mock data */ | |
return 15; | |
}; | |
class User { | |
id = 0; | |
static count: number = 0; | |
constructor( | |
public username: string, | |
public age: number | |
) { | |
this.id = ++User.count; | |
} | |
static { | |
User.count += userCount(); | |
} | |
} | |
console.log(User.count); // 15 | |
new User('John', 23); | |
new User('Suzi', 31); | |
console.log(User.count); // 17 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment