Last active
August 29, 2015 13:57
-
-
Save mnicovideo/9613891 to your computer and use it in GitHub Desktop.
socrates is dies, the exploited is not dies.
This file contains hidden or 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
Object.generate = Object.generate ? Object.generate : function(proto) { | |
function F() {} | |
if (!proto) { | |
return F; | |
} | |
if (typeof proto === 'function') { | |
F.prototype = new proto(); | |
return F; | |
} | |
if (typeof proto === 'object' && proto.constructor === Object) { | |
F.prototype = proto; | |
return new F(); | |
} | |
return proto; | |
}; | |
(function(global) { | |
var Human = global.Object.generate(); | |
Human.prototype.isHuman = function() { | |
return this instanceof Human; | |
}; | |
Human.prototype.isDies = function() { | |
return true; | |
}; | |
var Philosopher = global.Object.generate(Human); | |
Philosopher.prototype.isPhilosopher = function() { | |
return this instanceof Philosopher; | |
}; | |
Philosopher.prototype.isDies = function() { | |
return this.isHuman() && Human.prototype.isDies.call(this); | |
}; | |
var Punk = global.Object.generate(Philosopher); | |
Punk.prototype.isPunk = function() { | |
return this instanceof Punk; | |
}; | |
Punk.prototype.isDies = function() { | |
return false; | |
}; | |
Philosopher.prototype.isPunk = function() { | |
return this instanceof Punk; | |
}; | |
// ====================================== | |
console.log('=== Human ==='); | |
var aHuman = new Human(); | |
console.log(aHuman.isDies()); | |
console.log('=== Philosopher ==='); | |
var aPhilosopher = new Philosopher(); | |
console.log(aPhilosopher.isHuman()); | |
console.log(aPhilosopher.isPhilosopher()); | |
console.log(aPhilosopher.isDies()); | |
console.log('=== Punk ==='); | |
var aPunk = new Punk(); | |
console.log(aPunk.isPhilosopher()); | |
console.log(aPunk.isPunk()); | |
console.log(aPunk.isDies()); | |
console.log('=== Socrates ==='); | |
var socrates = new Philosopher(); | |
console.log(socrates.isHuman()); | |
console.log(socrates.isPhilosopher()); | |
console.log(socrates.isPunk()); | |
console.log(socrates.isDies()); | |
console.log('=== THE EXPLOITED ==='); | |
var exploited = new Punk(); | |
console.log(exploited.isHuman()); | |
console.log(exploited.isPhilosopher()); | |
console.log(exploited.isPunk()); | |
console.log(exploited.isDies()); | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment