Best option for strongly typed containers in javascript

I just discovered a way to create fake “classes” in javascript, but I wonder how you can store them and still get easy access to their functions in the IDE.

Like this:

function Map(){
   this.width = 0;
   this.height = 0;
   this.layers = new Layers();
}

Now I have a function that goes through XML and creates several Map () objects. If I store them under one variable, I can access them simply, for example:

map1 = new Map();
map1.height = 1;

But I do not know under what name they will be saved! So I thought I could save them like this:

mapArray = {};
mapArray['map1'] = new Map();

But you cannot access the following functions: (At least the completion of the IDE code will not pick it up)

mapArray['map1'].height = 1;

Then I thought this was the best solution:

function fetch(name){
    var fetch = new Map();
    fetch = test[name];
}

So I could write:

fetch('test').height = 1;

But it looks like it will generate a lot of overhead continuous copies of variables like this.

- ?

+5
2

, , , , / - , , . , Vector<> - ActionScript , Javascript.

[] javascript

, , , - , . .get(whatever), , [whatever], , . .set(whatever,value). , [].

, IDE, , - .

Update:

... -, JS, :

http://blog.thefrontside.net/javascript/learning-javascript-from-the-command-line

https://developer.mozilla.org/en/SpiderMonkey_Build_Documentation

, , "":

# js
js> function FooDataClass(){ this.data = "argh!"; }
js> function FooClass(){ this.get = GetStuff; this.put = PutStuff; this.stuff = new FooDataClass(); }
js> function PutStuff(name,stuff){ this[name]= this.stuff = stuff; }    
js> function GetStuff(name){ return this.stuff = this[name]; }     
js> f = new FooClass()       
[object Object]
js> f.put('bar', new FooDataClass())       
js> f.get('bar')    
[object Object]
js> f.get('bar').data
argh!
js> 

IDE .

+4

, JavaScript. ST-JS - Maven, Eclipse, Java. JavaScript . Java , , , IDE.

, API-, , - , JavaScript: DOM jQuery. , .

+1

All Articles