原文:點擊打開鏈接
var map = new Map();
map.put("a", "aaa");map.put("b","bbb");
map.put("cc","cccc");
map.put("c","ccc");
map.remove("cc");
var array = map.keySet();
for(var i in array) {
document.write("key:(" + array[i] +") <br>value: ("+map.get(array[i])+") <br>");
}
function Map(){
this.container = new Object();
}
Map.prototype.put = function(key, value){
this.container[key] = value;
}
return this.container[key];
}
Map.prototype.keySet = function() {
var keyset = new Array();
var count = 0;
for (var key in this.container) {
// 跳過object的extend函數
if (key == 'extend') {
continue;
}
keyset[count] = key;
count++;
}
return keyset;
}
Map.prototype.size = function() {
var count = 0;
for (var key in this.container) {
// 跳過object的extend函數
if (key == 'extend'){
continue;
}
count++;
}
return count;
}
Map.prototype.remove = function(key) {
delete this.container[key];
}