Skip to content

Instantly share code, notes, and snippets.

@whtswrng
Last active October 23, 2018 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whtswrng/1b6194eff692a81dd796d28199d320f7 to your computer and use it in GitHub Desktop.
Save whtswrng/1b6194eff692a81dd796d28199d320f7 to your computer and use it in GitHub Desktop.
class User {
constructor(roles) {
this.roles = roles;
}
getRoles() {
return this.roles;
}
}
class AdminUser extends User {}
const ordinaryUser = new User(['moderator']);
const adminUser = new AdminUser({role: 'moderator'},{role: 'admin'});
function showUserRoles(user) {
const roles = user.getRoles();
roles.forEach((role) => console.log(role));
}
showUserRoles(ordinaryUser);
showUserRoles(adminUser);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment