1、inheritprototype.js

;(function(){
    var s = {
        inheritObject:function(o){//对象继承封装
            var F = function(){};
            F.prototype = o;
            return new F();
        },
        inheritPrototype:function(subclass,supperclass){//原型继承封装
            var obj = this.inheritObject(supperclass.prototype);
            obj.constructor = subclass;
            subclass.prototype = obj;
        }
    };
    window.$ = window.s = s;//起别名并把闭包内的命名空间对象s暴露出去
})(window);

2、inheritprototype.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript" src="js/inheritprototype.js"></script>
</head>
<body>

</body>
<script type="text/javascript">
;(function(){
    function Shape(){//超类
        this.name = 'Lucy';
        this.type = '超体者'
    }
    Shape.prototype = {
        init:function(){
            var name = this.getname();
            var type = this.gettype();
            console.log(name);
            console.log(type);
        },
        getname:function(){
            return this.name;
        },
        gettype:function(){
           return this.type;
        }
    }
    function Triangle(){//子类
        Shape.apply(this);//this继承构造体
        this.sex = '女';
    }
    $.inheritPrototype(Triangle,Shape);//这里一定要注意,是先继承再拓展自己的原型方法,否则报错
    Triangle.prototype.getsex = function(){
       console.log(this.sex);
    }
    var o = new Triangle();
    o.init();//继承父元素的init()并执行
    o.getsex();//执行Triangle构造函数的方法
})();
</script>
</html>

最新文章

  1. 七种机器内部排序的原理与C语言实现,并计算它们的比较次数与移动次数。
  2. JavaScript 面向对象(二) —— 案例篇
  3. Java程序员要求具备的10项技能
  4. 使用squid配置透明代理并对上网行为进行控制
  5. iOS系统消息
  6. Spring第一天
  7. 如何安装nodejs
  8. ios kaifa
  9. [iOS]把16进制(#871f78)颜色转换UIColor
  10. Django数据操作
  11. 版本控制工具git入门
  12. linux里忘记root密码解决办法
  13. 【转】android TV CTS 4.0.3_r1测试
  14. Demo 示例控制输入光标位置
  15. 查看文章strncpy()功能更好的文章
  16. 201521123115《Java程序设计》第6周学习总结
  17. 设计模式——状态模式(C++实现)
  18. BZOJ_3170_[Tjoi2013]松鼠聚会_切比雪夫距离+前缀和
  19. C#使用ES
  20. 以ActiveMQ为例JAVA消息中间件学习【4】——消息中间件实际应用场景

热门文章

  1. FCKeditor 2.6.6在ASP中的安装及配置方法分享--ZZ转载自网络
  2. hrbustoj 2033 A Funny Game(对称博弈)
  3. .net core 14
  4. Spring注入值得2种方式:属性注入和构造注入
  5. 根据html生成Word文件,包含图片
  6. Cordova插件开发
  7. android usb挂载分析---vold处理内核消息
  8. Android启动脚本init.rc(2)
  9. w3school之JavaScript学习笔记
  10. php自学笔记3