|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (22) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
最后更新时间:2008-05-27
Array本来就是一个 hashmap
可以这样使用 var list = new Array(); list[sKey] = sValue |
|
| 返回顶楼 | |
|
最后更新时间:2008-05-27
小弟也来show一下自己的Map,基于mootools写的.望指教..
/**
* @author FHQ
* @realize the functions like java.util.Map
* All Known Subclasses:
* 1.com.citic.data.SendData
* 2.com.citic.data.ReturnData
*/
/**
* mootools-release-1[1].11.js
* |_com.citic.util.Map
*/
/**
* package com.citic.util.Map;
* import mootools-release-1[1].11.js;
*/
var Map = new Class({
initialize : function(){
this.list = new Array();
var $break = new Object();
},
put : function(key, value){
try{
$each(this.list,function(MapElement,index){
if(MapElement.key == key){
MapElement.value = value;
throw this.$break;
}
});
var MapElement = new Class({
initialize : function(){
this.key = null;
this.value = null;
}
});
MapElement.key = key;
MapElement.value = value;
this.list.include(MapElement);
}catch(e){
if(e != this.$break) throw e;
}
},
size : function(){
return this.list.length;
},
get : function(key){
var result = null;
try{
$each(this.list,function(MapElement,index){
if(MapElement.key == key){
result = MapElement.value;
throw this.$break;
}
});
}catch(e){
if(e != this.$break) throw e;
}
return result;
},
remove : function(key){
try{
$each(this.list,function(MapElement,index){
if(MapElement.key == key){
this.remove(MapElement);//this refer to this.list
throw this.$break;
}
},this.list);
}catch(e){
if(e != this.$break) throw e;
}
},
containsKey : function(key){
if(this.get(key) !=null){
return true;
};
return false;
},
keySet : function(){
var keySet = new Array();
$each(this.list,function(MapElement){
keySet[keySet.length] = MapElement.key;
});
return keySet;
},
values : function(){
var valueSet = new Array();
$each(this.list,function(MapElement){
valueSet[valueSet.length] = MapElement.value;
});
return valueSet;
},
clear : function(){
this.list.length = 0;
this.list = null;
this.list = new Array();
},
clone : function(){
var returnMap = new Map();
returnMap.list = this.list.copy();
return returnMap;
}
});
|
|
| 返回顶楼 | |
|
最后更新时间:2008-05-27
我想知道 是哪五个无知的人投票来的 没办法 菜鸟云集的地方 混不下去啊
说话没人能听懂 我说的很清楚吧? 引用 Object的原生属性你怎么处理?
引用 你这样做判断是否存在 会有问题
明明是自己不试 居然还说别人没试过 算了算了 没办法啊没办法 我给代码 去运行看看吧 var map = {};
map["key1"] = "Value1"; // 加入值对
map["key2"] = "Value2";
map["key3"] = "Value3";
if("valueOf" in map) { //判断是否存在
alert("OK");
}
自己回去好好翻一遍ECMA262 有解决的办法 具体哪页就不告诉你们了 |
|
| 返回顶楼 | |
|
最后更新时间:2008-05-27
在javascript实现MAP 有必要吗?
|
|
| 返回顶楼 | |
|
最后更新时间:2008-05-27
kaipingk@gmail.com 写道 在javascript实现MAP 有必要吗? 同感阿,在JS里实现Map,真的是,没法说了。 |
|
| 返回顶楼 | |
|
最后更新时间:2008-05-30
应该是很不错的。
Javascript 本不应该用于处理大量数据,页面如果有大量数据,也该考虑后台分页了。 |
|
| 返回顶楼 | |
|
最后更新时间:2008-05-30
这个也是会有需要用到的时候嘛
|
|
| 返回顶楼 | |
|
最后更新时间:2008-05-30
楼上是不是有几位 什么语言都没用过Map的?
有些程序员一直到退休都不会写也没用过Map和Hashmap |
|
| 返回顶楼 | |
|
最后更新时间:2008-05-31
csf178 写道 楼上是不是有几位 什么语言都没用过Map的?
有些程序员一直到退休都不会写也没用过Map和Hashmap 你怎么知道人间一身都不会写也没用过啊!:) |
|
| 返回顶楼 | |
|
最后更新时间:2008-05-31
kaipingk@gmail.com 写道 csf178 写道 楼上是不是有几位 什么语言都没用过Map的?
有些程序员一直到退休都不会写也没用过Map和Hashmap 你怎么知道人间一身都不会写也没用过啊!:) 我又不是神仙 只是猜一下而已 嘻嘻 因为我觉得你们说Js里面不需要Map很奇怪 我知道有很多程序员是这样的 喜欢硬编码 基本都不用Map这类高级排序或者查找结构的 |
|
| 返回顶楼 | |






