自调用参数在 babel-loader 中将其更改为未定义
Self-invoking argument changing this to undefined in babel-loader
我正在使用带有 babel-loader 的 Webpack,我看到了这个问题:babel-loader 将匿名自调用函数中的 this
agrument 更改为 undefined
而不是 this
。
例如:
(function (t1, t2) {
})(this, 'test')
转换为:
(function (t1, t2) {
})(undefined, 'test');
Babel 假定每个文件都是一个 (ES2015) 模块。模块的 this
在运行时具有值 undefined
。为了在尚不支持模块的环境中模拟正确的行为(此时的每个环境),Babel 将每个顶级 this
替换为 undefined
.
我正在使用带有 babel-loader 的 Webpack,我看到了这个问题:babel-loader 将匿名自调用函数中的 this
agrument 更改为 undefined
而不是 this
。
例如:
(function (t1, t2) {
})(this, 'test')
转换为:
(function (t1, t2) {
})(undefined, 'test');
Babel 假定每个文件都是一个 (ES2015) 模块。模块的 this
在运行时具有值 undefined
。为了在尚不支持模块的环境中模拟正确的行为(此时的每个环境),Babel 将每个顶级 this
替换为 undefined
.