I’m currently writing a feature for an interactive periodic table which dynamically displays the name of the element and other properties when you hover over the element. I have thought of three ways to do this and I am wondering which is the best, memory-wise and speed-wise, for loading this information.
-
make a class with an array ( new Array(“hydrogen”, “helium”, “lithium”,…etc.)), instantiating it, then accessing the info with object.arr[i]
-
make a class with a static array (otherwise, same as no.1), importing it, then accessing the info with class.arr[i]
-
put the information into an external xml file and accessing it from there.
The 3rd method seems excessive as you have to go through the hassle of adding event listeners for URLloader every time.
Is there any difference between the 1st and 2nd way? (What is happening in terms of memory when you are importing a class – is the entire array added to memory?)
I would go for the third method 🙂
Getting used to use xml for storing content is always good, and it’s only some lines of code:
In this case you could go for the hardcoded solution too, but I really prefer to have the content and the code separated. It’s easier to mantain everything if in the future you decide to add extra content to every cell (and as @weltraumpirat says, you don’t need to recompile everything when info changes)