I'm not new to JavaScript, but I've never really had too much in-depth knowledge of how it works. I'm currently developing some software for a cell phone that is done completely in JavaScript. Everything runs fine, except that once in a while the garbage collector kicks in, and everything stops momentarily.
The problem is that objects are constantly being destroyed and created. There are many objects that are also similar, but not the same.
The solution is simple: whenever an object is no longer needed, put it in a linked list that acts as a recycle bin. Whenever we're ready to create another object of a similar type (most of the same properties), get the object from the list and set it up as necessary. However, I'm not entirely sure on the conversion part.
I understand that every object in JavaScript is essentially just a hash table, but I'm still not exactly sure how I should approach the problem. I'll give an example of the problem below:
var type1 = Class.create({ ... });
var type2 = Class.create({ some of the same properties + some different ones });
Now I have a type1 that's not being used and I want to use it as a type2. What is the best way of doing this?