Created
February 21, 2011 07:18
-
-
Save cris/836768 to your computer and use it in GitHub Desktop.
Multi-class in JS
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 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