首页 > 其他 > 详细

call继承父级属性,prototype继承父级方法

时间:2017-08-26 13:20:16      阅读:269      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
</head>
<body>
    
</body>
<script type="text/javascript" >
// 通过call继承父级属性
    function A(){
        this.abc=12
    }
   
 function B(){
    // this → new B();
    A.call(this)
 }
 var obj = new B();
alert(obj.abc) //12

// 通过prototype继承父级方法

A.prototype.show=function(){
    alert(this.abc)
}

B.prototype.show=A.prototype.show; //tongguo prototype原型继承父级方法

obj.show() //12
</script> </html>

 

call继承父级属性,prototype继承父级方法

原文:http://www.cnblogs.com/model-zachary/p/7435067.html

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