我在 chrome 中发现,看不到 for in 循环的每一步。例如,使用 chrome 或 chrome canary 的调试器,在行中设置断点
for (var i in stuff)
下面的代码,当暂停时,点击 step into 直到该行
return n;
你可以看到for in循环会完成一次。我想看看for in循环的整个过程。所以问题是:如何在chrome中查看javascript for in循环的每一步?
function objectPlus(o, stuff) {
var n;
function F() {}
F.prototype = o;
n = new F();
n.uber = o;
for (var i in stuff) {
// I found in debuger, for in loop will finish in one step into,so you can't see the process of every property copy
n[i] = stuff[i];
}
return n;
}
var shape = {
name: 'shape',
toString: function() {
return this.name;
}
};
var twoDee = objectPlus(shape, {
name: '2D shape',
toString: function() {
return this.uber.toString() + ', ' + this.name;
}
});