首页 > 代码库 > js 继承的一个例子

js 继承的一个例子

<script type="text/javascript">
   function Animal(){
    this.species = "动物";
    this.action = function(){alert("会跑");};
  }
  function Cat(name,color){
    this.name = name;
    this.color = color;
  }
  function Cat(name,color){
       Animal.apply(this,arguments);
    this.name = name;
    this.color = color;
  }
  var cat1 = new Cat("大毛","黄色");
  alert(cat1.action()); 
</script>

  

js 继承的一个例子