【发布时间】:2012-10-05 00:18:23
【问题描述】:
我的代码看起来像这样:
function pathfind (start,end,map)
{
this.Init = function ()
{
this.open_node = new Array();
this.open_node.push(start);
console.log(this.open_node);
this.Loop();
}
this.Loop = function ()
{
//Some code here
}
this.Init();
}
由于某种原因,当我将“开始”推送到 this.open_node 并记录其值时,我得到“未定义”。但是,经过一些错误测试后,我意识到注释掉 this.Loop();在 this.Init 中,push 正常运行,console.log 返回 [start]。谁能解释为什么会发生这种行为?
编辑:我在打电话
pathfind({x:2,y:2},{x:24,y:24},parsemap(25,25));
【问题讨论】:
-
调用 pathfind() 的行在哪里。你所传递的可能会产生影响......
-
感谢您指出这一点。我的测试表明数据类型无关紧要,但你可以这样做。
-
如果你在 console.log 语句之前放置一个断点会发生什么?
-
无效。我应该意识到 Chrome 控制台是异步的,所以不会很好玩。
标签: javascript console execution