js里的继承
1、new做的事情a、创建一个Object对象【O】。b、将new后面的function对象的【自身属性】和【prototype的属性】
赋值给【O】
2、js中的访问“对象的属性”例如a.b是有先后顺序的,即先访问【自身的属性】,然后访问【prototype的属性】。
<script>
persion=function()
{
this.print=function()
{
alert('print persion');
}
}
persion.prototype.ask=function()
{
alert('persion ask');
}
child=function()
{
persion.call(this);//将persion的【自身属性】作为child的【自身属性】
}
//把persion的【自身属性】和【prototype的属性】都作为child的【prototype的属性】
child.prototype=new persion();
child.prototype.constructor=child;//修改child的constructor
child.prototype.print=function()
{
alert('child print');
}
var c=new child();
c.print();
c.ask();
</script>