課程
/前端開發(fā)
/JavaScript
/JavaScript深入淺出
這個 抽象類的實現類怎么寫?老師求教
2015-07-22
源自:JavaScript深入淺出 9-1
正在回答
function DetectorBase(){
throw new Error('Abstract class can not be invoked directly!');
}
DetectorBase.prototype.detect=function(){
console.log('Detection starting');
DetectorBase.prototype.stop=function(){
console.log('Detector stopped.');
DetectorBase.prototype.init=function(){
throw new Error('Error');
function LinkDetector(){
LinkDetector.prototype=Object.create(DetectorBase.prototype);
LinkDetector.prototype.constructor=LinkDetector;
var link=new LinkDetector();
/**重寫init*/
link.init=function(){
console.log(this);
link.detect();
link.stop();
link.init();
我是這樣理解的,不知道對不對。你參考參考。
Web_dlf
舉報
由淺入深學習JS語言特性,且解析JS常見誤區(qū),從入門到掌握
4 回答抽象類中子類為什么不能調用父類的非抽象方法?
4 回答抽象類不明白啊
2 回答抽象類代碼錯誤
1 回答關于抽象類中繼承的問題
1 回答抽象類那里是不是寫錯了?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-02-01
function DetectorBase(){
throw new Error('Abstract class can not be invoked directly!');
}
DetectorBase.prototype.detect=function(){
console.log('Detection starting');
}
DetectorBase.prototype.stop=function(){
console.log('Detector stopped.');
}
DetectorBase.prototype.init=function(){
throw new Error('Error');
}
function LinkDetector(){
}
LinkDetector.prototype=Object.create(DetectorBase.prototype);
LinkDetector.prototype.constructor=LinkDetector;
var link=new LinkDetector();
/**重寫init*/
link.init=function(){
console.log(this);
}
link.detect();
link.stop();
link.init();
我是這樣理解的,不知道對不對。你參考參考。