Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

javascript - 阻止Webpack尝试解决“此”(Prevent Webpack from trying to resolve “this”)

I'm learning more about Webpack and am running into an issue where my use of this at the top level is getting replaced by (void 0) .

(我正在学习有关Webpack的更多信息,并且遇到了一个问题,在该问题上,我在顶级使用this正被(void 0)代替。)

For context, the environment that is reading this JS requires my functions to exist on this .

(对于上下文,正在读取此JS的环境要求我的函数存在于this 。)

I assume it's converting this into (void 0) because it can't resolve the value of this .

(我以为它转换this(void 0)因为它不能解析的值this 。)

My configuration right now is very basic:

(我现在的配置非常基础:)

{
  entry: inputPath,
  output: {
    path: outputPath,
    filename: outputFilename
  }
}

The JS in question looks like this:

(有问题的JS看起来像这样:)

Object.keys(commands).forEach((handler) => {
  this[handler] = commands[handler];
});

And then the part of the Webpack compilation that I'm having trouble with looks like this:

(然后,我遇到问题的Webpack编译部分如下所示:)

Object.keys(o).forEach(n => {
  (void 0)[n] = o[n]
})

So my question is, how can I tell Webpack to leave this alone?

(所以我的问题是,我怎么能告诉的WebPack离开this人吗?)

Form Googling around I can't seem to find a specific answer to the problem.

(围绕Google搜索,我似乎无法找到该问题的具体答案。)

  ask by Jody Heavener translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...