数码资讯
js使用删除来继承示例代码
复制代码代码如下所示: 通过冒充对象的方式继承 函数A(颜色){ 这颜色=颜色; This.AshowColor = function () { document.writeln(颜色:这); } } 函数B(颜色,名称){ 方法 / /的赋值,调用构造函数 this.newmethod =一; T
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
复制代码代码如下所示:
通过冒充对象的方式继承
函数A(颜色){
这颜色=颜色;
This.AshowColor = function () {
document.writeln(颜色:这);
}
}
函数B(颜色,名称){
方法 / /的赋值,调用构造函数
this.newmethod =一;
This.newMethod(彩色);
然后删除对A的引用,因此他不能调用
删除this.newmethod;
这bname =名称;
this.bshowname =函数(){
document.writeln(bname:+,bname);
}
}
无功obja =新一(红色);
ObjA.AshowColor();
document.writeln();
无功objb =新的B(黑
ObjB.AshowColor();
ObjB.BshowName();
document.writeln();
通过冒充对象的方式继承
函数A(颜色){
这颜色=颜色;
This.AshowColor = function () {
document.writeln(颜色:这);
}
}
函数B(颜色,名称){
方法 / /的赋值,调用构造函数
this.newmethod =一;
This.newMethod(彩色);
然后删除对A的引用,因此他不能调用
删除this.newmethod;
这bname =名称;
this.bshowname =函数(){
document.writeln(bname:+,bname);
}
}
无功obja =新一(红色);
ObjA.AshowColor();
document.writeln();
无功objb =新的B(黑
ObjB.AshowColor();
ObjB.BshowName();
document.writeln();
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。