欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js 采用delete實(shí)現(xiàn)繼承示例代碼

 更新時(shí)間:2014年05月20日 17:30:15   作者:  
這篇文章主要介紹了js如何采用delete實(shí)現(xiàn)所謂的繼承,下面有個(gè)不錯(cuò)的示例,大家可以參考下
復(fù)制代碼 代碼如下:

//采用對(duì)象冒充的方式實(shí)現(xiàn)js繼承
function A(color) {
this.Acolor = color;
this.AshowColor = function() {
document.writeln("Acolor: " + this.Acolor);
}
}

function B(color, name) {
//將newMethod賦值A(chǔ),調(diào)用A的構(gòu)造函數(shù)
this.newMethod = A;
this.newMethod(color);
//然后刪除對(duì)A的引用,這樣以后不能調(diào)用他
delete this.newMethod;

this.Bname = name;
this.BshowName = function() {
document.writeln("Bname: " + this.Bname);
}
}

var objA = new A("red");
objA.AshowColor();
document.writeln("----------------");
var objB = new B("black", "demo");
objB.AshowColor();
objB.BshowName();
document.writeln("----------------");

相關(guān)文章

最新評(píng)論