-
Notifications
You must be signed in to change notification settings - Fork 0
webpack plugins
ythy edited this page Oct 13, 2017
·
2 revisions
this
的指向问题:
-
CleanPathPlugin.prototype.apply = function(compiler) {
此函数里this
不指向全局,需要转换。 -
this.mPath.forEach((elem)=>{
这里this
arrow函数指向CleanPathPlugin, 函数调用需要通过call()
来进行
function CleanPathPlugin( path, option ){
this.options = option || {};
this.mPath = path;
}
function cleanHandle(){
if(this.mPath && this.mPath.length > 0){
this.mPath.forEach((elem)=>{
removedFolder.call(this, elem);
});
}
}
CleanPathPlugin.prototype.apply = function(compiler) {
var _this = this;
compiler.plugin("compile", function() {
if(!debug)
cleanHandle.call(_this);
});
};
module.exports = CleanPathPlugin;
tell me how get back to sunshine