为什么我无法访问 Chrome 调试器中 $.each 循环中的变量

Why can't I access variables within an $.each loop in Chrome's debugger?

本文关键字:each 变量 循环 调试器 访问 Chrome 为什么      更新时间:2023-09-26

我想使用调试器检查$.each循环中test_data(传递到populateChildTable的对象)中的一些属性。当我尝试使用调试器访问它们时,我收到undefined错误

var populateChildTable = function(test_data) {
    $.each(test_data.children, function(index, el) {
        $('#my_children tbody')[0].appendChild(createChildRow(el)); // breakpoint here
    })
})

Chrome 版本 48.0.2564.71 测试版(64 位)

这与这个铬错误有关。

test_data$.each回调范围内可用,您可以使用 console.log(test_data) 而不是 debugger; 来验证这一点。开发工具优化会导致这种行为,您可以在上面链接的线程中阅读有关此行为的信息。