每当我面试被问到原型继承的时候,总是写下这段代码

function Fuck() {
  this.species = 'Not specified';
};

Fuck.prototype.fuck = function () {
  console.log('Fuck' + this.species);
};

function FuckHuman() {
  this.species = 'Human';
  Fuck.call(this);
}


FuckHuman.prototype = Object.create(Fuck.prototype);

// Set the "constructor" property to refer to FuckHuman
FuckHuman.prototype.constructor = FuckHuman;

function FuckYou() {
  this.name = 'You';
  FuckHuman.call(this);
}

FuckYou.prototype = Object.create(FuckHuman.prototype);
FuckYou.prototype.constructor = FuckYou;

FuckYou.prototype.fuck = function () {
  console.log('Fuck ' + this.name);
}

var fuckYou = new FuckYou ();
fuckYou.fuck();

你可能感兴趣的:(每当我面试被问到原型继承的时候,总是写下这段代码)