Skip to content

Instantly share code, notes, and snippets.

@cris
Created February 21, 2011 07:18
Show Gist options
  • Save cris/836768 to your computer and use it in GitHub Desktop.
Save cris/836768 to your computer and use it in GitHub Desktop.
Multi-class in JS
function User() {
this.name = 'Sasha';
}
User.prototype.login = function() {
console.log("Hello, " + this.name);
};
function Admin(self) {
if (self) {
self.admin = this;
}
this.title = 'admin';
}
Admin.prototype.moderate = function() {
console.log("Hello, moderator " + this.title + " " + this.name);
};
var user = new User();
user.login();
user.admin = new Admin(user);
user.admin.moderate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment