Recently, I uncovered a clever method for creating fake 'classes' in JavaScript, but now I'm curious about how to efficiently store them and easily access their functions within an IDE.
Here is an example:
function Map(){
this.width = 0;
this.height = 0;
this.layers = new Layers();
}
Currently, I have a function that iterates through XML data and generates multiple instances of the Map() object. When I group these objects under a single variable, accessing them works seamlessly, like so:
map1 = new Map();
map1.height = 1;
However, I am unsure about the specific name they will be stored under. This led me to consider saving them in this manner:
mapArray = {};
mapArray['map1'] = new Map();
Yet, attempting to access the functions using this structure seems to present challenges with IDE code completion:
mapArray['map1'].height = 1;
As an alternative, I contemplated the following solution:
function fetch(name){
var fetch = new Map();
fetch = test[name];
}
This could allow me to utilize the following syntax:
fetch('test').height = 1;
Although, I'm concerned that such a method might lead to significant overhead from continuous variable copying. Is there a simpler approach that I may be overlooking?