所以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) –
點擊'我旁邊的控制檯輸出,並閱讀那裏的解釋。 –