Map Schlüssel, Klassen, (N)-Baum abbilden

Hallo, ich hab mich schon an die Syntax gewöhnt, aber ich muss es ja auch inhaltlich begreifen. Ich bitte, alle Fragen auch hinsichtlich Effizienz zu beantworten.

  1. Map, komplexe Strukturen… Wie wird der Schlüssel einer Map (über die Attribute des Schlüssels) gebildet? Irgendwie muss es da ja eine linearisierte Form geben.

  2. Wann wird der Schlüssel gebildet?

  3. Wann verändert sich der Schlüssel?

  4. Klassen… Gibt es Klassen in JS? Ich bräuchte parent, childs und value/Inhalt.
    ( 5) Wenn nicht, dann Map? )

  5. Baum abbilden, siehe 4)… Effizient mir verschachtelter Map möglich?

Danke, wer mir ein paar Hinweise geben mag.

Ich gibe auch nochmal ein Beispiel:

Erstellen:
[javascript]var obj = {
‘subObject’: {
‘key’: ‘value’
},
‘another object’: {
‘some key’: ‘some value’,
‘another key’: ‘another value’,
‘an array’: [ ‘this’, ‘is’, ‘ok’, ‘as’, ‘well’ ]
}
}[/javascript] How to fill a Javascript map with many static key/value pairs efficiently? - Stack Overflow

Durchlaufen:
[javascript]for (var key in obj) {
if (obj.hasOwnProperty(key)) {
// prüfe irgendwie weitere Verschachtelung von obj[key] …
console.log(key + " -> " + obj[key]);
}
}[/javascript] How do I loop through or enumerate a JavaScript object? - Stack Overflow

Was ist hieran falsch?:

[javascript]function Node(id) {
this.parent = null;
this.childs = [];
this.id = id;
/**
* @param {Node} child
* @returns {undefined}
/
this.addChild = function (child) {
child.parent = this;
this.childs[this.childs.length] = child; // besser gefällt mir .push()…
};
/
*
* @returns {Array}
*/
this.getChilds = function () {
return this.childs;
};
}[/javascript]
[javascript]var a = new Node(-1);

a.addChild(0);

a.getChilds[x].addChild(1);[/javascript]
Er sagt mir, addChild ist undefined, bei getChilds[x] .

Zweitens: Ich hab eine Map of Map of Map of usw. usf.

Wie durchlaufe ich alle key,value rekursiv und wie komme ich an alle key,value >>>auf Ebene 2 und 3 von unten<<< heran?

Versuch:

[javascript]hallo = function (s, key, val) {
if (typeof val !== ‘number’) {
s += ‘start’;
for (var child in val) {
s += hallo(s, child, val[child]);
}
s += ‘stop’;
} else {
s += ‘blatt’;
}
return s;
};[/javascript]
Da kommt so etwas ähnliches wie Stack overflow …

Edit: Man denke sich oben bitte, a.getChilds()[x].addChild(1); also die ()-Klammern, dazu!