javascript原型prototype(3)

小练习:

View Code
<script language="javascript"> 
function parent(name,sex){
this.name=name;
this.sex=sex;
this.show=function(){
alert("今天你吃了吗");
}
}
function child(name,sex){
parent.call(this,name,sex);
}

var par=new parent("小张","");
parent.prototype.say=function(){
document.write("<br/>姓名:"+this.name+" 性别:"+this.sex);
}

par.say();
/*
默认new 出来的child对象的原型就是它构造函数child的prototype属性的值
此时改变了new出来child对象的值,值应该为(new parent).prototype属性的值.
*/
child.prototype=new parent();
var ch=new child("小明","");
ch.say();
</script>





posted @ 2012-04-08 07:58  unbreakable  阅读(176)  评论(0编辑  收藏  举报