Hallo erstmal!
Ich hab folgendes Problem. Ich versuche eine einfach verkettete Liste zu programmieren und irgendwie merkt sich der browser nicht meine variable next.
Ich poste einmal den Source-Code
function Column(name) {
this.name = name;
this.next = null;
this.setName = function(name) {
this.name = name;
}
this.getName = function() {
return this.name;
}
this.setNext = function(next) {
this.next = next;
}
this.getNextName = function() {
document.write(this.next.getName());
}
this.getNext = function() {
//document.write(next.getName();
return this.next;
}
this.hasNext = function() {
if (this.next == null) return false;
if (this.next != null) return true;
}
}
Nun erstelle ich eine Instanz mit
column1 = new Column("erstes Element");
column2 = new Column("zweites Element");
columns = column1.setNext(column2);
document.write(columns.getNext().getName());
Nun sollte eigentlich der Browser "zweites Element" ausgeben. Tut er aber nicht :(. Vielleicht weiß jemand von euch die Lösung auf mein Problem :).
lg
Christian