======================
<script>
function parent(){
this.x=10;
this.add = function ()
{
}
}
function child(){
}
child.prototype=new parent();
var childObj=new child();
alert(childObj.add);
</script>
function parent(){
this.x=10;
this.add = function ()
{
}
}
function child(){
}
child.prototype=new parent();
var childObj=new child();
alert(childObj.add);
</script>
除了child.prototype=new parent();
还需将child.prototype.constructor指回child构造函数
还需将child.prototype.constructor指回child构造函数
<script>
function parent(){
this.x=10;
this.add = function ()
{
}
}
function child(){
parent.call(this);
}
var childObj=new child();
alert(childObj.add);
</script>
function parent(){
this.x=10;
this.add = function ()
{
}
}
function child(){
parent.call(this);
}
var childObj=new child();
alert(childObj.add);
</script>