我有类似以下代码:
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”来打开节点时并记录其值时,我得到了“undefined”。然而,在进行一些错误测试后,我意识到在这个Init中注释掉this.Loop();会导致push函数正常工作,并且console.log会像应该的那样返回[start]。有人能解释为什么会出现这种行为吗?
编辑:我正在调用
pathfind({x:2,y:2},{x:24,y:24},parsemap(25,25));