zl程序教程

您现在的位置是:首页 >  后端

当前栏目

JS继承实例分析

2023-06-13 09:14:06 时间
复制代码代码如下:

functionP(name){
this.name=name;

this.p1=function(){
alert("ParentConstructor");
}
returnthis;
}
functionC(name,id){
//this.method=P;
//this.method(name);//1stmethod
//P.call(this,name);//2ndmethod
P.apply(this,newArray(name));//3rdmethod
this.id=id;
this.dis=function(){
alert(this.name);
}
}
functiondis(){
alert(this.name);
}
functiont(){
varcc=newC("N","Id");
cc.dis();
cc.p1();
}