Inheritance with $.extend

by Kriem

HTML

<h1></h1>
<h2></h2>
<h3></h3>

JavaScript

function Cat(){
    
    this.name = 'cat';
};

function Animal(){
    
    this.isAnimal = true;
};

function Pet(){
 
    this.isPet = true;
};

Cat.prototype = new Animal();
Cat.prototype = $.extend({}, Cat.prototype, new Pet());

var cat = new Cat();

$('h1').text(cat.name);
$('h2').text(cat.isAnimal || 'no animal');
$('h3').text(cat.isPet || 'no pet');

console.log(cat);