JavaScript继承方式实例
2023-06-13 09:14:25 时间
functionparent(){
this.x=10;
}
functionchild(){
varparentObj=newparent();
for(varpinparentObj)this[p]=parentObj[p];
}
varchildObj=newchild();
alert(childObj.x);
functionparent(){
this.x=10;
}
functionchild(){
this.parent=parent;
this.parent();
deletethis.parent;
}
varchildObj=newchild();
alert(childObj.x);
functionparent(){
this.x=10;
}
functionchild(){
parent.call(this);
}
varchildObj=newchild();
alert(childObj.x);
原型抄写
functionparent(){
}
parent.prototype.x=1;
functionchild(){
}
for(varpinparent.prototype)child.prototype[p]=parent.prototype[p];
child.prototype.y=2;
varchildObj=newchild();
alert(childObj.x);
functionparent(string){
varchild=newFunction("this.x=10;"+string);
returnchild;
}
varchild=newparent("this.y=20;");
varchildObj=newchild();
alert(childObj.y);
functionparent(){
this.x=10;
}
functionchild(){
}
child.prototype=newparent();
varchildObj=newchild();
alert(childObj.x);
functionparent(){
this.x=10;
}
functionchild(){
varret=newparent();
ret.y=20;
returnret;
}
varchildObj=newchild();
alert(childObj.x);
相关文章
- Javascript原型链您了解多少
- JavaScript正则表达式(完整版)
- JavaScript 中的遍历详解编程语言
- javascript实现文字隐藏详解编程语言
- javascript判断是否支持WebAssembly详解编程语言
- 使用javascript访问XML数据的实例
- Javascript日期对象的dateAdd与dateDiff方法
- JavaScript异步调用框架(Part6-实例&模式)
- javascript检测浏览器类型和版本的代码
- JavaScript与Div对层定位和移动获得坐标的实现代码
- JavaScript性能陷阱小结(附实例说明)
- javascript学习笔记(十九)节点的操作实现代码
- JavaScript对象创建及继承原理实例解剖
- javascript使用NodeList需要注意的问题
- JavaScript实现页面实时显示当前时间的简单实例
- javascript显示用户停留时间的简单实例
- javascript树形导航菜单实例代码
- javascript中简单的进制转换代码实例
- Javascript事件实例详解
- javascript判断是手机还是电脑访问网页的简单实例分享
- JavaScript常用验证函数实例汇总
- javascript中数组array及string的方法总结
- Javascript字符串对象的常用方法简明版
- PHP和javascript常用正则表达式及用法实例
- Javascript中innerHTML用法实例分析
- javascript二维数组转置实例
- javascript原型链继承用法实例分析
- JavaScript数组函数unshift、shift、pop、push使用实例
- 一个JavaScript用逗号分割字符串实例