課程
/前端開發(fā)
/JavaScript
/JavaScript深入淺出
為什么沒有OOP的PPT,我打算做筆記,但是實在是懶得手打了
2017-07-05
源自:JavaScript深入淺出
正在回答
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>探測器</title>
<script type="text/javascript">
!function(global){
function DetectorBase(configs){
if(!this instanceof DetectorBase){
throw new Error('Do not invoke without new.');
}
this.configs = configs;
this.analyze();
DetectorBase.prototype.detect = function(){
throw new Error('Not implemented');
};
DetectorBase.prototype.analyze = function(){
console.log('analyzing...');
this.data = '###data###';
function LinkDetector(links){
if(!this instanceof LinkDetector){
this.links = links;
DetectorBase.apply(this,arguments);
function ContainerDetector(containers){
if(!this instanceof ContainerDetector){
this.containers = containers;
//inherit first
inherit(LinkDetector,DetectorBase);
inherit(ContainerDetector, DetectorBase);
LinkDetector.prototype.detect = function(){
console.log('Loading data:'+this.data);
console.log('Link detection started');
console.log('Scaning links:'+this.links);
ContainerDetector.prototype.detect = function(){
console.log('Scaning containers:'+this.containers);
//prevent from being alerted
Object.freeze(DetectorBase);
Object.freeze(DetectorBase.prototype);
Object.freeze(LinkDetector);
Object.freeze(LinkDetector.prototype);
Object.freeze(ContainerDetector);
Object.freeze(ContainerDetector.prototype);
//export to global object
? ?Object.defineProperties(global,{
LinkDetector:{value:LinkDetector},
ContainerDetector:{value:ContainerDetector},
DetectorBase:{value:DetectorBase}
});
function inherit(subClass,superClass){
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
}(this);
var cd = new ContainerDetector('#abc #def #ghi');
var ld = new LinkDetector('http://www.taobao.com http://www.tmall.com http://www.baidu.com');
cd.detect();
ld.detect();
</script>
</head>
<body>
</body>
</html>
舉報
由淺入深學(xué)習JS語言特性,且解析JS常見誤區(qū),從入門到掌握
4 回答oop的PPT有嗎?
2 回答OOP的PPT
2 回答大贊 但是這章為什么 沒有PPT下載啊..
5 回答我兩個打印出來的都是number ,為什么?
1 回答為什么沒有函數(shù)后面的ppt
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2017-07-18
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>探測器</title>
<script type="text/javascript">
!function(global){
function DetectorBase(configs){
if(!this instanceof DetectorBase){
throw new Error('Do not invoke without new.');
}
this.configs = configs;
this.analyze();
}
DetectorBase.prototype.detect = function(){
throw new Error('Not implemented');
};
DetectorBase.prototype.analyze = function(){
console.log('analyzing...');
this.data = '###data###';
};
function LinkDetector(links){
if(!this instanceof LinkDetector){
throw new Error('Do not invoke without new.');
}
this.links = links;
DetectorBase.apply(this,arguments);
}
function ContainerDetector(containers){
if(!this instanceof ContainerDetector){
throw new Error('Do not invoke without new.');
}
this.containers = containers;
DetectorBase.apply(this,arguments);
}
//inherit first
inherit(LinkDetector,DetectorBase);
inherit(ContainerDetector, DetectorBase);
LinkDetector.prototype.detect = function(){
console.log('Loading data:'+this.data);
console.log('Link detection started');
console.log('Scaning links:'+this.links);
};
ContainerDetector.prototype.detect = function(){
console.log('Loading data:'+this.data);
console.log('Link detection started');
console.log('Scaning containers:'+this.containers);
};
//prevent from being alerted
Object.freeze(DetectorBase);
Object.freeze(DetectorBase.prototype);
Object.freeze(LinkDetector);
Object.freeze(LinkDetector.prototype);
Object.freeze(ContainerDetector);
Object.freeze(ContainerDetector.prototype);
//export to global object
? ?Object.defineProperties(global,{
LinkDetector:{value:LinkDetector},
ContainerDetector:{value:ContainerDetector},
DetectorBase:{value:DetectorBase}
});
function inherit(subClass,superClass){
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
}
}(this);
var cd = new ContainerDetector('#abc #def #ghi');
var ld = new LinkDetector('http://www.taobao.com http://www.tmall.com http://www.baidu.com');
cd.detect();
ld.detect();
</script>
</head>
<body>
</body>
</html>