87,909
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
var father=function(){
this.name="father";
}
var child=function(){
child.prototype=new father();
}
var son=new child();
alert(child.prototype.name);
alert(son.name);
</script>
<script type="text/javascript">
var father=function(){
this.name="father";
}
var child=function(){
//child.prototype=new father();//放到child外面执行
}
child.prototype=new father();
var son=new child();
alert(child.prototype.name);
alert(son.name);
</script>
var father=function(){
this.name="father";
}
var child=function(){
// child.prototype=new father();
child.prototype.name = "123"; //改变副本,不改变引用,
}
var son=new child();
alert(child.prototype.name);
alert(son.name);
<script type="text/javascript">
var father=function(){
this.name="father";
}
var child=function(){
//child.prototype=new father();//放到外面,在son对象创建后执行
}
var son=new child();
child.prototype=new father();//在son已经创建后执行,再来设置son的构造函数的prototype已经对son没有任何意义了,son不会回过头来继承father任何成员。
alert(child.prototype.name);
alert(son.name);
</script>
var father=function(){
this.name="father";
}
var child=function (){
child.prototype=new father();
}
var son=new child();
alert(child.prototype.name);
alert(son.name);
var son1=new child();
alert(son1.name);
var father=function(){
this.name="father";
}
var child=function(){
// child.prototype=new father();
child.prototype.name = "123"; //改变副本,不改变引用,
}
var son=new child();
alert(child.prototype.name);
alert(son.name);