Javascript Webpack所需变量超出范围

Javascript Webpack所需变量超出范围,javascript,scope,webpack,Javascript,Scope,Webpack,我正在使用Webpack将我的JavaScript捆绑在一起。为什么线条图构造函数中的颜色变量不可用 // top of the file var {colors} = require('../../global-config.js'); var a = 3; // colors is required correctly, and is available on this line // if I am stepping through the code. var LineChart =

我正在使用Webpack将我的JavaScript捆绑在一起。为什么线条图构造函数中的颜色变量不可用

// top of the file
var {colors} = require('../../global-config.js');
var a = 3; // colors is required correctly, and is available on this line 
// if I am stepping through the code.

var LineChart = function (svgElement, data, options) {
this.dates = []; // colors is unavailable at this point. Why?
在文件末尾:

module.exports = LineChart;

我甚至可以在构造函数中要求变量,但我不想这样做,因为我必须在
折线图
的原型上的每个函数中要求它。

我认为调试该问题需要更多关于代码的详细信息。我想到的一件事是,如果在函数体中根本没有使用折线图构造函数的闭包中的值,那么VM可能正在优化这些值。因此,它们可能不会显示在调试器中。您可以设置一个小的演示项目进行研究吗?如果您在控制台中查看它,那么它将是未定义的,除非它在函数中使用。你是说如果你在函数中指定了颜色-结果是未定义的吗?如果是这样的话,那么需要更多的代码/演示