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

时间:2016-02-26 23:47:14

标签: javascript jquery google-chrome scope

我想使用调试器检查test_data循环中populateChildTable(传递给$.each的对象)中的一些属性。当我尝试使用调试器访问它们时出现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 beta(64位)

1 个答案:

答案 0 :(得分:1)

这与this铬虫有关。

test_data回调范围内提供了

$.each,您可以使用console.log(test_data)代替debugger;来验证这一点。开发工具优化会导致此行为,您可以在上面链接的线程中阅读该内容。