JavaScript继承方式
2010-10-27 16:48
375 查看
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);
function parent(){ this.x=10; } function child(){ this.parent=parent; this.parent(); delete this.parent; } var childObj=new child(); alert(childObj.x);
function parent(){ this.x=10; } function child(){ parent.call(this); } var childObj=new child(); alert(childObj.x);
原型抄写
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);
function parent(string){ var child=new Function("this.x=10;"+string); return child; } var child=new parent("this.y=20;"); var childObj=new child(); alert(childObj.y);
function parent(){ this.x=10; } function child(){ } child.prototype=new parent(); var childObj=new child(); alert(childObj.x);
function parent(){ this.x=10; } function child(){ var ret=new parent(); ret.y=20; return ret; } var childObj=new child(); alert(childObj.x);
相关文章推荐
- javascript的继承实现的几种方式
- JavaScript程序中实现继承特性的方式总结
- 详述JavaScript实现继承的几种方式
- javascript中的继承的实现方式
- JavaScript是如何实现继承的(六种方式)
- JavaScript中实现继承的几种方式的使用和分析
- JavaScript六种继承方式
- JavaScript 继承方式(2)
- JavaScript深入之继承的多种方式和优缺点
- JavaScript实现继承的方式优化
- JavaScript中继承方式详解
- javascript创建对象、对象继承的实用方式详解
- js(javascript) 继承的5种实现方式
- 实现JavaScript中继承的三种方式
- JavaScript五种继承方式
- JavaScript实现继承(六种方式)
- Javascript实现继承的6种方式
- JavaScript实现继承方式
- Javascript之继承(原型链方式)
- JavaScript的六种继承方式(推荐)