javascript 继承

 
    function Animal(){};//动物
    function Mammal(){};//哺乳类
    function Canine(){};//犬科
    function Dog(){};//
    function Cat(){};//
    
     Animal.prototype.respire = function(){
        alert("交换氧气与二氧化碳!");
         };
   Mammal.prototype = new Animal();
   Canine.prototype = new Mammal();
   Dog.prototype = new Canine();
   Cat.prototype = new Mammal();
   
   function isAnimal(obj){
        return obj instanceof Animal;
   }; 
   var dog = new Dog();
   var cat = new Cat();
   document.writeln(isAnimal(dog));
   
   document.writeln("respire" in dog);
   document.writeln("respire" in cat); 

对象关系图:

原文地址:https://www.cnblogs.com/you000/p/2843381.html