奇怪的javascript错误 - 对象消失

时间:2015-08-24 18:28:11

标签: javascript html5

我遇到了javascript问题。我有一个名为“lista_rectangulos”的对象列表,其中包含如下对象:{x:350,y:150,ancho:40,alto:30}

当我使用此功能时出现问题:

function canBeInserted(pos_x,pos_y,ancho,alto,excluded_rectangle){

        var ret = true;


        for (i = 0; i < lista_rectangulos.length; i++) 
        { 
            if (lista_rectangulos[i] === excluded_rectangle){
                continue;
            }
            if (pos_x>(lista_rectangulos[i].x) && pos_x<(lista_rectangulos[i].x+lista_rectangulos[i].ancho) && pos_y>(lista_rectangulos[i].y) && pos_y<(lista_rectangulos[i].y+lista_rectangulos[i].alto)) {
                ret = false;

            }
        }   


        return ret;
    }

问题在于,当我调用该函数时,它会从列表中推出元素“excluded_rectangle”(该变量的名称并不意味着它应该从列表中排除,仅来自比较),以及这不应该发生。看:

 console.log(lista_rectangulos[i]);

if(canBeInserted(lista_rectangulos[i].x,lista_rectangulos[i].y,lista_rectangulos[i].alto,lista_rectangulos[i].ancho, lista_rectangulos[i]))

{
    console.log(lista_rectangulos[i]);

                      (more code...)

}

这是控制台输出:

Object {x: 250, y: 150, ancho: 30, alto: 30}
undefined

第一个显示对象,第二个显示该对象已被删除。我不明白为什么。

0 个答案:

没有答案
相关问题