简体   繁体   English

如何在JavaScript中调试库函数的重写代码?

[英]How to debug overridden code of a library function in javascript?

This is my code snippet. 这是我的代码段。 As you can see the drawNodes function is overridden from the dagre-d3.js library for drawing directed graphs. 如您所见,dagre-d3.js库覆盖了drawNodes函数,用于绘制有向图。 However, when I assign a breakpoint at the line which starts with 'renderer.drawNodes', and 'step into', the control goes inside the library. 但是,当我在以“ renderer.drawNodes”和“ step into”开头的行上分配断点时,控件进入了库内部。 If I step over, however, it skips this function and goes to the next line after the end of the function. 但是,如果我跨步,它将跳过此功能,并在功能结束后转到下一行。

var oldDrawNodes = renderer.drawNodes();
renderer.drawNodes(function(graph, root) {
  var svgNodes = oldDrawNodes(graph, root);
  svgNodes.each(function(u) { d3.select(this).classed(graph.node(u).nodeclass, true); });
  return svgNodes;
});

My purpose is to debug the overridden code, I would like to watch the expression value of var svgNodes and more functionality which I plan to write there. 我的目的是调试覆盖的代码,我想观察var svgNodes的表达式值以及打算在此处编写的更多功能。

How do I do this? 我该怎么做呢? Thanks. 谢谢。

Don't step into renderer.drawNodes() . 不要进入renderer.drawNodes() Make sure that your code is broken up into enough separate lines so you can set your breakpoint exactly where you want it. 确保将代码分成足够多的单独行,以便可以将断点精确设置在所需的位置。 Then set a breakpoint on the desired line line and let the debugger RUN until it hits that breakpoint (not stepping, but running). 然后在所需的行上设置一个断点,并让调试器运行,直到碰到该断点(不是步进,而是运行)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM