0
嗨我想在Javascript中實現LinkedList。當我給我的節點分配一個值時,當我使用我的getter時,它似乎不存儲它。例如:私人對象沒有設置數據
var Node =function() {
var _data;
var _next ={};
var that = this;
that.getData = function() {
return _data;
};
that.setData = function(data) {
that._data = data;
};
that.getNext = function() {
return _next;
};
that.setNext = function(next) {
that._next = next;
};
return that;
};
不會工作與:
var nodeObj = new Node();
nodeObj.setData("hello");
console.log(nodeObj.getData());
因爲您將值賦給'that._data',但是您正在從'_data'中讀取它。 – Thomas
感謝我與JavaScript新,這仍然讓我有點困惑。 – Muffin
你想要建立什麼?當我使用鏈接列表時,在此列表上執行的操作通常是特定的,我停止嘗試實現任何通用LL,或者向節點添加任何邏輯。它通常是使用LL的代碼,也就是在我的實現中管理和修改節點。 – Thomas