首页 > 编程语言 > 详细

javascript实现继承的一种方式

时间:2015-05-25 20:02:37      阅读:290      评论:0      收藏:0      [点我收藏+]
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库如何实现继承的方法。

javascript实现继承的一种方式

原文:http://www.cnblogs.com/hubing/p/4528496.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!