简体   繁体   English

JavaScript console.log执行顺序?

[英]JavaScript console.log execution order?

I have code that looks something like this: 我的代码看起来像这样:

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();
}

For some reason when I push "start" to this.open_node and I log its value, I get "undefined". 出于某种原因,当我将“start”推入this.open_node并记录其值时,我得到“未定义”。 However, after some bug testing I realized that commenting out this.Loop(); 但是,经过一些错误测试,我意识到这个评论出来了.Loop(); in this.Init causes push to function properly and console.log to return [start] as it should. 在this.Init中导致push正常运行,console.log按原样返回[start]。 Can anyone explain why on earth this behavior would occur? 任何人都可以解释为什么会发生这种行为?

EDIT: I'm calling 编辑:我在打电话

pathfind({x:2,y:2},{x:24,y:24},parsemap(25,25));

After further research I found that console.log doesn't execute immediately in Chrome. 经过进一步研究后,我发现console.log不会立即在Chrome中执行。 Hence the outdated reports. 因此过时的报道。

Your code executes pathfind function that returns undefined (and it should be this way) but you wait for result from this.Init function. 你的代码执行返回undefined pathfind函数(它应该是这样的),但你等待this.Init函数的结果。 Should probably execute it instead of pathfind . 应该执行它而不是pathfind

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

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