admin管理员组文章数量:1435808
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". However, after some bug testing I realized that menting 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?
EDIT: I'm calling
pathfind({x:2,y:2},{x:24,y:24},parsemap(25,25));
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". However, after some bug testing I realized that menting 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?
EDIT: I'm calling
pathfind({x:2,y:2},{x:24,y:24},parsemap(25,25));
Share
Improve this question
edited Oct 5, 2012 at 0:38
Jack Guy
asked Oct 5, 2012 at 0:18
Jack GuyJack Guy
8,5338 gold badges60 silver badges88 bronze badges
4
- Where's the line that calls pathfind(). What you're passing may have an impact... – Lee Taylor Commented Oct 5, 2012 at 0:21
- Thanks for pointing that out. My testing showed that data types didn't matter, but here you go. – Jack Guy Commented Oct 5, 2012 at 0:22
- what happens if you put a breakpoint just before console.log statement ? – sbr Commented Oct 5, 2012 at 1:24
- No effect. I should have realized the Chrome console is asynchronous so wouldn't play nice. – Jack Guy Commented Oct 5, 2012 at 22:50
2 Answers
Reset to default 6After further research I found that console.log doesn't execute immediately in 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. Should probably execute it instead of pathfind
.
本文标签: JavaScript consolelog execution orderStack Overflow
版权声明:本文标题:JavaScript console.log execution order? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745641303a2667876.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论