this.ObjArr = {};
this.Count = 0;
//新增
this.Add = function(key, value) {
if (this.ObjArr.hasOwnProperty(key)) {如果已經存在, 添加
}
else {
🎜> return true;
}
}
//是否包含某項
this.Contains = function(key) {
else {
//return;
}
}
//移除
this.Remove = function(key) {
if (this.Contains(key)) { ); this.Count- -;
}
}
//清空
this.Clear = function() {
this.ObjArr = {}; this.Count = 0;>
//員工
function employee(id, userName) {
this.id = id;
this.userName = userName;
function test() {
var ht = new HashTable();
var tmpEmployee = null;
for (var i = 1; i o. );
ht.Add(i, tmpEmployee);
}
for (var i = 1; i //alert(ht.ObjArr[i].userName);
}
> alert(ht.Contains(1)); //false
//alert(ht.GetValue(1)); //異常
//alert(ht.GetValue(1)); //異常 //alert(ht。 > var result = ht.GetValue(2);
if (result != null) {
alert("Employee Id:" result.id "fUserName: alert("Employee Id:" result.id ";UserName: alert("Employee Id:" result.id "; 🎜> ht.Add(2, "這一個key已經存在!"); //Add無效
//ht.Clear(); //清空
alert(ht.Count);
}