js 采用delete實現繼承示例代碼
更新時間:2014年05月20日 17:30:15 作者:
這篇文章主要介紹了js如何采用delete實現所謂的繼承,下面有個不錯的示例,大家可以參考下
復制代碼 代碼如下:
//采用對象冒充的方式實現js繼承
function A(color) {
this.Acolor = color;
this.AshowColor = function() {
document.writeln("Acolor: " + this.Acolor);
}
}
function B(color, name) {
//將newMethod賦值A,調用A的構造函數
this.newMethod = A;
this.newMethod(color);
//然后刪除對A的引用,這樣以后不能調用他
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("----------------");
相關文章
Bootstrap Table從服務器加載數據進行顯示的實現方法
Bootstrap-Table是一個Boostrap的表格插件,能夠將JSON數據直接顯示在表格中。接下來通過本文給大家分享Bootstrap Table從服務器加載數據進行顯示的實現方法,感興趣的朋友一起看看吧2016-09-09

