我试图重写使用require.js使用es6导入的旧应用程序.其中一个使用的库是Backbone和Underscore.要创建一个大包并将es6预编译到es5,我使用带有babel-loader的Webpack.Bundle被创建,但当我在浏览器中加载它时,我收到以下错误:
Uncaught TypeError: Cannot read property '_' of undefined
Run Code Online (Sandbox Code Playgroud)
看起来Underscore中的'this'在创建的bundle.js中是未定义的,所以root._给了我错误.
// Baseline setup
// --------------
// Establish the root object, `window` in the browser, or `global` on the server.
var root = this;
// Save the previous value of the `_` variable.
var previousUnderscore = root._;
// Establish the object that gets returned to break out of a loop iteration.
var breaker = {}
Run Code Online (Sandbox Code Playgroud)
有谁遇到过同样的问题?