javascript数组效率

时间:2012-02-28 12:51:38

标签: javascript vector

为了精确定位具有非常不稳定的鼠标坐标的物体,我跳了一两步,豪华地使用了大量的矢量索引。但这是否意味着我在向量中为6000左右的值分配空间?它减缓了什么?或者可以吗?

// ---- starting position ---- 
    mouse.x        = screen.w / 2; 
    mouse.xd       = mouse.x; 
    camera.x       = scene.startX || 0; 
    camera.z       = scene.startZ || 0; 
    camera.targetX = scene.targetX || 0; 
    camera.targetZ = scene.targetZ || 0; 
    var picIndex=new Array(1,101,2101,4101,4401,5401,6401,6301,2301,2001); // pics position in room
    var myPics=new Array(); // 
    myPics[1]="This is picture 1"; // 
    myPics[101]="This is picture 2";
    myPics[2101]="This is picture 3";
    myPics[4101]="This is picture 4";
    myPics[4401]="This is picture 5";
    myPics[5401]="This is picture 6";
    myPics[6401]="This is picture 7";
    myPics[6301]="This is picture 8";
    myPics[2301]="This is picture 9";
    myPics[2001]="This is picture 10";


    // then show picture identification


    setInterval(function () { 
    uniqueID = (camera.targetZ*2)+camera.targetX+3201;
    showInfo = document.getElementById('dynamic_info');
    showInfo.innerHTML = myPics[uniqueID] ; 
        //document.getElementById('dynamic_info2').innerHTML =   camera.targetX ;
        //document.getElementById('dynamic_info3').innerHTML = uniqueID; 
        //document.getElementById('dynamic_info4').innerHTML = camera.z ;
        //document.getElementById('npoly').innerHTML = npoly * 2; 
        //fps = 0; 
        //npoly = 0; 
    }, 500); // update every 0.5 seconds 

1 个答案:

答案 0 :(得分:2)

它被视为稀疏数组。 More details