Copy Code code as follows:
function parent () {
this.x=10;
}
function Child () {
var parentobj=new parent ();
For (var p in parentobj) this[p]=parentobj[p];
}
var childobj=new child ();
alert (childobj.x);
Copy Code code as follows:
function parent () {
this.x=10;
}
function Child () {
This.parent=parent;
This.parent ();
Delete this.parent;
}
var childobj=new child ();
alert (childobj.x);
Copy Code code as follows:
function parent () {
this.x=10;
}
function Child () {
Parent.call (this);
}
var childobj=new child ();
alert (childobj.x);
Prototype transcription
Copy Code code as follows:
function parent () {
}
Parent.prototype.x=1;
function Child () {
}
For (var p in Parent.prototype) child.prototype[p]=parent.prototype[p];
child.prototype.y=2;
var childobj=new child ();
alert (childobj.x);
Copy Code code as follows:
function Parent (string) {
var child=new Function ("this.x=10;" +string);
return to child;
}
var child=new parent ("THIS.Y=20;");
var childobj=new child ();
alert (CHILDOBJ.Y);
Copy Code code as follows:
function parent () {
this.x=10;
}
function Child () {
}
Child.prototype=new parent ();
var childobj=new child ();
alert (childobj.x);
Copy Code code as follows:
function parent () {
this.x=10;
}
function Child () {
var ret=new parent ();
ret.y=20;
return ret;
}
var childobj=new child ();
alert (childobj.x);