JavaScript console.log执行顺序? [英] JavaScript console.log execution order?

查看:501
本文介绍了JavaScript console.log执行顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码看起来像这样:

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

出于某种原因,当我将 start推送到this.open_node并登录时它的值,我得到未定义。但是,经过一些错误测试,我意识到将this.Loop();注释掉了。 init会导致push正常运行,console.log会按原样返回[start]。谁能解释为什么这种现象会发生?

For some reason when I push "start" to this.open_node and I log its value, I get "undefined". However, after some bug testing I realized that commenting out this.Loop(); in this.Init causes push to function properly and console.log to return [start] as it should. Can anyone explain why on earth this behavior would occur?

编辑:我正在呼叫

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


推荐答案

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

After further research I found that console.log doesn't execute immediately in Chrome. Hence the outdated reports.

这篇关于JavaScript console.log执行顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆