第一种
// map实现
var map = new Object();
map.put = function (key,value){
var s = "map." + key + ' = "' + value + '";';
eval(s);
}
map.get = function(key){
var v = eval("map." + key + ";");
return v;
}
map.keySet = function(){
var keySets = new Array();
for(key in map){
if(!(typeof(map[key])=="function")){
keySets.push(key);
}
}
return keySets;
}
/*
* use example
*/
/*
map.put("a","Tom");
map.put("b","Nick");
var keys = map.keySet();
for(i in keys){
key = keys[i];
alert("key:" + key + " value:" + map.get(key));
}
* /
/*
* end example
*/
第二种 关联数组模拟map
var map = {};