简体   繁体   English

如何在Google Chrome DevTools的lambda调用中设置断点?

[英]How to set a breakpoint at a lambda call in Google Chrome DevTools?

I use Babel and Google Chrome Developer Tools with JavaScript source maps enabled. 我使用启用了JavaScript源地图的Babel和Google Chrome开发者工具。 Given this code 鉴于此代码

function myFunc(elements) {
  return elements
    .map(element => element.value)
    .filter(value => value >= 0);
}

how can I pause execution at execution of lambda function element => element.value ? 如何在执行lambda function element => element.value暂停执行? If I set a breakpoint at line of .map(element => element.value) it will only pause when map is executed, but not when the lambda function is executed. 如果我在.map(element => element.value)行设置一个断点,它只会在执行map时暂停,但不会在执行lambda函数时暂停。

This feature is finally available (at least in Google Chrome 58). 此功能最终可用(至少在Google Chrome 58中)。 Click on the line number of the line of your lambda you like to debug (here line 3). 单击要调试的lambda行的行号(此处为第3行)。 Then activate the marker in your lambda (here the second) by clicking it. 然后通过单击激活lambda中的标记(此处为第二个)。 Further, I disabled the first marker here, which would pause on the map call (not the lambda): 此外,我在这里禁用了第一个标记,这将在map调用(而不是lambda)上暂停:

设置断点

When your program runs and hits the breakpoint, it will pause and you can inspect variables: 当你的程序运行并命中断点时,它会暂停,你可以检查变量:

在断点处暂停

You can use the debugger keyword to signal the debugger to pause at that location and it can be inserted just like any JavaScript statement. 您可以使用debugger关键字来指示调试器在该位置暂停,并且可以像任何JavaScript语句一样插入调试器。

function myFunc(elements) {
  return elements
    .map(element => {debugger; return element.value})
    .filter(value => value >= 0);
}

You can do as follows: 你可以这样做:

    function myFunc(elements) {
      return elements
        .map(element => {
           element.value
        })
        .filter(value => value >= 0);
    }

This way you can add a breakpoint in line element.value 这样,您可以在line element.value添加断点

Couldn't find a way to get it work without code changing. 没有代码更改就找不到让它工作的方法。
If anybody can find a way please tell. 如果有人能找到方法请告诉。

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

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