gpt4 book ai didi

javascript - Webpack 插件开发 - 函数调用父函数的参数

转载 作者:行者123 更新时间:2023-12-03 05:11:44 25 4
gpt4 key购买 nike

在 Webpack 的文档中列出了此代码片段。我想知道callback()函数实际上是做什么的。

function MyPlugin() {
this.startTime = Date.now();
this.prevTimestamps = {};
}

MyPlugin.prototype.apply = function(compiler) {
compiler.plugin('emit', function(compilation, callback) {

var changedFiles = Object.keys(compilation.fileTimestamps).filter(function(watchfile) {
return (this.prevTimestamps[watchfile] || this.startTime) < (compilation.fileTimestamps[watchfile] || Infinity);
}.bind(this));

this.prevTimestamps = compilation.fileTimestamps;
callback();
}.bind(this));
};

module.exports = MyPlugin;

最佳答案

这来自 Webpack@v2,但我相信它的解释和应用类似:

https://webpack.js.org/pluginsapi/compiler/

The Compiler exposes a run method which kickstarts all compilation work for webpack. When that is done, it should call the passed in callback function. All the tail end work of logging stats and errors are done in this callback function.

关于javascript - Webpack 插件开发 - 函数调用父函数的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41786006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com