貌似老师的代码错了,有哪位大神纠正下
!function(global){
function DetectorBase(configs){
if (!this instanceof DetectorBase) {
throw new Error('Do not invoke without new.')
}
this.configs=configs;
this.analyze();
}
}(this);
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);
}
function inherit(subClass,superClass){
subClass.prototype=Object.create(superClass.prototype)
subClass.prototype.constructor=subClass;
}
inherit(LinkDetector,DetectorBase);
inherit(ContainerDetector,DetectorBase);
LinkDetector.prototype.detect=function(){
console.log('Loading data:'+this.data);
console.log('link detection started.');
console.log('Scaning link:'+this.links);
};
ContainerDetector.prototype.detect=function(){
console.log('Loading data:'+this.data);
console.log('Container detection started.');
console.log('Scaning containers:'+this.containers);
}
Object.defineProperties(global,{
LinkDetector:{value:LinkDetector},
ContainerDetector:{value:ContainerDetector},
DetectorBase:{value:DetectorBase}
});
var a=new ContainerDetector('#abc');
var b=new LinkDetector('http://www.baidu.com')
a.detect;
b.detect;VM25187:11 Uncaught ReferenceError: DetectorBase is not defined

