javascript实现继承的一种方式

function extend(Child, Parent) {

    var F = function(){};
    F.prototype = Parent.prototype;
    Child.prototype = new F();
    Child.prototype.constructor = Child;
    Child.uber = Parent.prototype;
  }

 

使用的时候,方法如下
  extend(Cat,Animal);
  var cat1 = new Cat("大毛","黄色");
  alert(cat1.species); // 动物

这个extend函数,就是YUI库如何实现继承的方法。

posted @ 2015-05-25 17:56  北斗极星  阅读(134)  评论(0)    收藏  举报