手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JavaScript继承方式实例
JavaScript继承方式实例
摘要:复制代码代码如下:functionparent(){this.x=10;}functionchild(){varparentObj=newp...

复制代码 代码如下:

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中createElement的两种创建方式

Javascript进制转换实例

JavaScript里实用的原生API汇总

javascript函数特点实例

JavaScript常用数组算法小结

JavaScript中实现继承的三种方式和实例

简介JavaScript中charAt()方法的使用

javascript实现Table排序的方法

JavaScript Date对象详解

javascript操作ul中li的方法

精品推荐
分类导航