0

我正在用 JavaScript 制作碰撞检测器。我想制作一个树形结构,以便制作一个复杂的对象。

有一个大数组,包括孩子在内的所有对象都是数组的一部分。其中有些是孩子,有些是父母。每个项目都有children,parentroot属性,如果发生碰撞,它会冒泡到父项。

我想出了两种识别物体的方法。

  1. 提供对象 ID

  2. 直接引用对象就像"node1.root = someOtherObject".

我也想知道哪个更快

//1
if(object1.root === root.id){/*code here*/}//id based identification (literally)
        //19253 === 19253

//or 2
if(object1.root === root){/*code here*/}//object based identification
     //[Object] === [Object]
4

1 回答 1

1

两者在性能方面将相同。请检查以下链接。

http://jsben.ch/#/Y9jDP

于 2017-02-22T05:22:30.467 回答