所以CONSOLE.LOG之前删除节点,我在JS创建了一个标准的链表类,它完美地workds但这种情况发生,例如/ .....链表中删除在JavaScript
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;
}
相关:[Chrome的JavaScript控制台是否懒惰评估数组?](http://stackoverflow.com/questions/4057440/is-chromes-javascript-console-lazy-about-evaluating-arrays) –
点击'我旁边的控制台输出,并阅读那里的解释。 –