I am making a collision detector in JavaScript. I want to make a tree structure so that I can make a complex object.
There is one big array and all the objects including children are part of the array.
Some of them are child and others are parents. Each item has children
, parent
and root
property and if a collision happens, it bubbles up to the parent.
I came up with 2 ways to identify objects.
Give objects IDs
Quote object directly like
"node1.root = someOtherObject"
.
I also want to know which is faster
//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]