Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Forked from k33g/gist:778460
Created January 13, 2011 19:58
Show Gist options
  • Save rwaldron/778480 to your computer and use it in GitHub Desktop.
Save rwaldron/778480 to your computer and use it in GitHub Desktop.
function Human(){
var that = this;
var name="John Doe";
that.getName=function(){return name;}
that.setName=function(value){name=value;}
return that;
}
function Man(){
var that = this.prototype = new Human();
this.prototype.constructor = Man;
var nickName = "Johnny";
that.getNickName=function(){return nickName;}
that.setNickName=function(value){nickName =value;}
that.toString = function(){return "Hello i am "+that.getName()+" aka "+nickName;}
return that;
}
var bob = new Man(); bob.setName("Bob"); bob.setNickName("Bobby");
var bill = new Man(); bill.setName("Bill"); bill.setNickName("Billy");
console.log(bob.toString());
console.log(bill.toString());
Human.prototype.helloWorld = function(){return "Hello World by "+ this.getName();}
console.log(bob.helloWorld());
console.log(bill.helloWorld());
console.log(bob);
console.log(bill);
function SuperHeroe(){
var that = this.prototype = new Man();
this.prototype.constructor = SuperHeroe;
var power = "?";
that.getPower = function(){return power};
that.setPower = function(value){power = value;}
return that;
}
var clarkkent = new SuperHeroe();
clarkkent.setName("Clark Kent");
clarkkent.setNickName("Smallville");
clarkkent.setPower("flying");
var peterparker = new SuperHeroe();
peterparker.setName("Peter Parker");
peterparker.setNickName("Pete");
peterparker.setPower("climbing");
console.log(clarkkent.toString()+" "+clarkkent.getPower());
console.log(peterparker.toString()+" "+peterparker.getPower());
console.log(clarkkent.helloWorld());
console.log(peterparker.helloWorld());
console.log(clarkkent);
console.log(peterparker);
Human.prototype.ditBonjour = function(){return "Salut à tous par "+ this.getName();}
console.log(clarkkent.ditBonjour());
console.log(peterparker.ditBonjour());
console.log(bob.ditBonjour());
console.log(bill.ditBonjour());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment