JavaScript控制台.log执行顺序?

JavaScript控制台.log执行顺序?,javascript,console,execution,Javascript,Console,Execution,我有这样的代码: 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 () {

我有这样的代码:

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_节点并记录其值时,会得到“undefined”。然而,在一些bug测试之后,我意识到注释掉这个.Loop();在这种情况下,Init会使push正常工作,并使console.log按其应该的方式返回[start]。有人能解释为什么会发生这种行为吗

编辑:我打电话来

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

您的代码执行
pathfind
函数,该函数返回
undefined
(应该是这种方式),但您等待
此.Init
函数的结果。可能应该执行它,而不是
pathfind

在进一步研究后,我发现console.log不会在Chrome中立即执行。因此,报告过时了

调用pathfind()的行在哪里。你所传递的可能会产生影响…谢谢你指出这一点。我的测试表明,数据类型无关紧要,但现在开始。如果在console.log语句之前放置一个断点,会发生什么?没有效果。我应该意识到Chrome控制台是异步的,所以不会玩得很好。对不起,我省略了一行重要的代码(this.Init();)。我进一步研究了一下,发现console.log不会像alert那样立即执行。算了吧\