javascript - 无法从 Chrome 控制台看到变量,但可以在代码中访问
问题描述
为什么可以从方法内部访问变量,但不能从浏览器控制台访问?
我有以下打字稿代码,使用 angular6,ng serve
在 Windows 10,当前 Chrome 上运行。
import * as d3 from "d3"; // from "npm i d3 --save" version 5.7
// picking a member of d3, nothing magical about "scaleLinear" here
console.log("see", d3.scaleLinear) // it prints ok, ƒ linear() {...
// angular component code fragment below
somefunction() {
console.log("see again", d3.scaleLinear) // it prints ok, again
// add a break here
}
我将代码驱动到某个功能。在休息时,当我尝试时在 Chrome 控制台中:
> console.log(d3.scaleLinear)
它抛出一个错误:
VM2012:1 Uncaught ReferenceError: d3 is not defined
at eval (eval at push../src/app/user-sel/user-sel.component.ts.UserSelComponent._resyncYSel (user-sel.component.ts:58), <anonymous>:1:13)
at UserSelComponent.push../src/app/user-sel/user-sel.component.ts.UserSelComponent._resyncYSel (user-sel.component.ts:58)
at UserSelComponent.push../src/app/user-sel/user-sel.component.ts.UserSelComponent.selYSel (user-sel.component.ts:166)
at Object.eval [as handleEvent] (UserSelComponent.html:75)
at handleEvent (core.js:21673)
at callWithDebugContext (core.js:22767)
at Object.debugHandleEvent [as handleEvent] (core.js:22470)
at dispatchEvent (core.js:19122)
at core.js:19569
at HTMLSpanElement.<anonymous> (platform-browser.js:993)
如何直接在控制台中访问 d3?我错过了什么?我查看了有关此主题的旧 SO 问题52332640,但找不到确凿的答案。
解决方案
推荐阅读
- c - linux socket通信延迟
- html - 如何在标题文本后面显示背景图像?
- android - 寻找 React Native Android App Crash 的原因
- loops - 如何在“迭代”表单中使用函数“count”?
- java - 使用 Java 的 AES 加密
- python - 无法使用 python 在 aws cdk 中写入策略文档
- python-3.x - 如何访问file2中的file1
- json - Kotlin:使用 Jackson 将集合映射到 json 数组
- javascript - Kendo Grid Popup Template 将数据绑定到第二个 Popup
- azure - 执行后将管道活动记录到数据库