【发布时间】:2017-02-10 14:09:25
【问题描述】:
所以,我在 js 中创建了一个标准的链表类,它运行良好,但例如 /.....
var myRef = new LinkedList() //let's say with vals 1->2->3
console.log(myRef) //2->3 They are both the same!!!! even though delete happens later in code!!!
myRef.deleteFirst();
console.log(myRef) //2->3 They are both the Same!!
LinkedList.prototype.deleteFirst = function() {
if (this.head.next == null) {
return;
}
var dummy = this.head.next.next;
var value = this.head.next.data;
delete this.head.next;
this.head.next = dummy;
this.head.length -= 1;
return value;
}
【问题讨论】:
-
点击控制台输出旁边的
i并阅读那里的解释。
标签: javascript data-structures linked-list prototype this