Skip to content

Instantly share code, notes, and snippets.

@AliN11
Last active August 5, 2019 04:17
Show Gist options
  • Save AliN11/458f0c7ff42b03dcd6d937ba764fabd9 to your computer and use it in GitHub Desktop.
Save AliN11/458f0c7ff42b03dcd6d937ba764fabd9 to your computer and use it in GitHub Desktop.
class User {
private rawUsername: string;
get userName(): string {
return "The fullname is: " + this.rawUsername;
}
set userName(newName: string) {
if (newName.length > 10) {
newName = newName.substr(0, 10);
}
this.rawUsername = newName;
}
}
let e = new User;
e.userName = 'abcdefghijklmnopq';
console.log(e.userName); // abcdefghij
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment