Skip to content

Instantly share code, notes, and snippets.

@obaranovskyi
Last active January 17, 2022 05:27
Show Gist options
  • Save obaranovskyi/3c9114d171b3424fc5c906158b3c39ee to your computer and use it in GitHub Desktop.
Save obaranovskyi/3c9114d171b3424fc5c906158b3c39ee to your computer and use it in GitHub Desktop.
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