国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JavaScript繼承方式實例

2019-11-21 00:10:11
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

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);

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 温州市| 墨江| 文昌市| 南开区| 沙坪坝区| 建始县| 财经| 开化县| 博客| 无棣县| 烟台市| 财经| 西安市| 莱西市| 台东县| 永嘉县| 绩溪县| 新蔡县| 石门县| 临高县| 兴国县| 中西区| 洪雅县| 谢通门县| 额尔古纳市| 玛多县| 池州市| 石河子市| 台中县| 香港| 株洲县| 从江县| 壤塘县| 建湖县| 兴仁县| 通州区| 大兴区| 清流县| 措勤县| 化州市| 新晃|