【发布时间】:2016-10-26 15:32:40
【问题描述】:
可能是一个愚蠢的问题,但它仍然让我有点卡住,不是 100% 确定答案。
所以我有一个 index.html 文件,它调用 example.js 文件中的一个函数(只是为了澄清而添加它):
function sinusGraph() {
var plotstart = 0,
plotrange = 20,
stepsize = 0.5; // not in use right now
var yValues, xValues;
function sinusValues(startinput, stopinput)
{
return d3.range(startinput, stopinput+1).map(function(i)
{
return Math.sin(i);
})
};
function xAxisValues(startinput, stopinput)
{
return d3.range(startinput, stopinput+1).map(function(i)
{
return i;
})
};
xValues = xAxisValues(plotstart, plotrange);
yValues = sinusValues(plotstart, plotrange); };
例如,用浏览器中声明的变量编写“xValues”,返回“xValues is not defined(...)”。
删除“var xValues”让它成为一个全局变量确实返回值。
我的问题:
浏览器的工具控制台看不到函数中的非全局变量?
如果是这种情况,那么这是查找您错误创建的潜在全局变量的好工具吗?
- 除了在声明变量的函数中使用 console.log(myVariable) 之外,还有什么方法可以在浏览器的工具控制台中查看这些变量?
【问题讨论】:
-
设置一个断点并在变量被命中时检查它,在代码中添加一个 console.log 行并写入值。
标签: javascript global-variables console.log