我正在用 JavaScript 制作碰撞检测器。我想制作一个树形结构,以便制作一个复杂的对象。
有一个大数组,包括孩子在内的所有对象都是数组的一部分。其中有些是孩子,有些是父母。每个项目都有children
,parent
和root
属性,如果发生碰撞,它会冒泡到父项。
我想出了两种识别物体的方法。
提供对象 ID
直接引用对象就像
"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]