拷贝继承

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>

</style>

</head>
<body>

<script type="text/javascript">
function A()
{
    this.abc = 12
    alert(this.abc);
}
A.prototype.show = function()
{
    alert(this);
}
//new A().show();
//(new A).show();
function B()
{
    //此时this => new B();
    A.call(this);
}
for(var i in A.prototype)//让B拷贝A的属性
{
    B.prototype[i]=A.prototype[i];
}

var obj = new B();
alert(obj.abc);
</script>
</body>
</html>

 

posted @ 2017-01-20 14:47  萤子  阅读(115)  评论(0)    收藏  举报