这段代码有什么问题?我想做一些类似于循环链表的东西。
<script type="text/javascript" charset="utf-8">
function LinkedText(text, nextLinkedText) {
this.text = text;
this.next = nextLinkedText;
this.AsNext= function() {
this.text = this.next.text;
this.next = this.next.next;
return this;
}
}
var first = new LinkedText('first')
var last = new LinkedText('last', first);
first.next = last;
alert(first.text); //show 'firts'
alert(first.AsNext().text); //show 'last'
alert(first.AsNext().text); //show 'last' not 'first' why?
alert(first.AsNext().text); //show 'last'
alert(first.AsNext().text); //show 'last' not 'first' why?
</script>