(function() { window['XR'] = {}; var midContainer = new Array(); var mapContainer = new Array(); var MAPID = 0; function Map(mid) { var type = typeof (mid); if ((type != "string") && (type != "number")) { throw "Map id must be a string or number!"; } for (var _c = 0; midContainer[_c]; _c++) { if (mid == midContainer[_c]) throw "You have already created Map : " + mid; } var identify = MAPID++; midContainer[identify] = mid; mapContainer[identify] = {}; mapContainer[identify]["id"] = mid; this.id = mid; this.prefix = "K_"; this.toString = function() { return "This is a map object!"; } } Map.prototype.getMapId = function() { return this.id; } Map.prototype.getMapIndex = function() { var index = -1; for (var _i = 0; mapContainer[_i]; _i++) { if (this.id == mapContainer[_i]["id"]) { index = _i; } } return index; } Map.prototype.put = function(key, value) { if ( typeof (key) != "string") { throw "key must be a string!"; } if ( typeof (value) == "function") { throw "value shouldn't be a function!"; } if (this.trimStr(key) == "") { throw "key is empty!"; } var index = -1; index = this.getMapIndex(); if (index != -1) { key = this.prefix + key; mapContainer[index][key] = value; } } Map.prototype.get = function(key) { var index = -1; index = this.getMapIndex(); var value = ""; if (index != -1) { var _tV = mapContainer[index]; key = this.prefix + key; value = (_tV.hasOwnProperty(key)) ? _tV[key] : "You haven't save this key's value!"; } else { value = "Current Map has lost connection!"; } return value; } Map.prototype.deleteKey = function(key) { var index = -1; index = this.getMapIndex(); key = this.prefix + key; var _tV = mapContainer[index]; if (_tV.hasOwnProperty(key)) { delete _tV[key]; } } Map.prototype.clearMap = function() { var index = -1; index = this.getMapIndex(); var maxId = MAPID - 1; if (index <= maxId) { for (var t = index; t < maxId; t++) { mapContainer[t] = mapContainer[t + 1]; midContainer[t] = midContainer[t + 1]; } mapContainer[maxId] = null; midContainer[maxId] = null; this.id = null; this.toString = null; MAPID--; } } Map.prototype.trimStr = function(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); } Map.prototype.isEmpty = function() { var index = -1; index = this.getMapIndex(); if (index != -1) { for (var attr in mapContainer[index]) { //alert(mapContainer[index][attr]); if (attr != "id") { return false; } } } return true; } Map.prototype.showMap = function() { var index = -1; index = this.getMapIndex(); var str = ""; if (this.id != null) { str = "Map:\t" + this.id + "\n"; for (var attr in mapContainer[index]) { if (attr != "id") { str += attr + ":\t" + mapContainer[index][attr] + "\n"; } } } else { str = "This Map doesn't exist!"; } alert(str); return str; } window['XR']['Map'] = Map; })() //TEST CODES------------ function test() { with (XR) { var m1 = new Map("ddd"); m1.put("dd", "dfdfdf"); m1.put("dd2", "8yeah!"); //alert(m1.get("dd")); //alert(m1.isEmpty()); m1.deleteKey("dd"); m1.clearMap(); m1.showMap(); } } test(); //-----------------
详细解决方案
javascript 兑现 Map 工具包
热度:600 发布时间:2013-01-27 13:56:17.0
相关解决方案
- javascript ie6兼容的有关问题
- javascript window open在ie中设立不起作用,求解决
- javascript 字符串拼接效率有关问题
- JavaScript 自动生成图片并合并有关问题
- 不走"<script type='text/javascript'>"标签咋回事
- <script type="javascript/text">的有关问题
- 用servlet+jsp+javascript+jdbc做个简单的办公自动化系统流程,该如何解决
- 怎么打开 javascript:SetData(2010,5,10)
- javaScript = == ===区别,该怎么解决
- javascript 怎么验证name=xx.xx的radio表单
- form action 和 javascript 的提交問題解决方法
- javascript,该怎么处理
- javascript,该如何处理
- javascript 选中文字 但是保存样式 标签
- 新人求问,J2EE方向,html,css,javascript,vml要学到什么程度?解决思路
- javascript 请求servlet兑现将函数中定义的变量作为参数
- javascript 不懂,该如何处理
- javascript 不懂解决方法
- JavaScript 大局函数求实例,高分求
- javaScript 里面 如何知道Object 对象的长度
- javascript 函数调用有什么有关问题,请
- javascript 中文本框中数字如何比较
- javascript IE通过,火狐,google浏览器不过解决思路
- javascript rsa加密/java使用Cipher.getInstance("RSA/ECB/PKCS1Padding")解密,该如何处理
- IE javascript start()函数解决方案
- 关于RTMP 播放器(DELPHI C# FLASH JAVASCRIPT)解决思路
- Chrome Javascript Click 事件,该如何解决
- javascript 实出_blank跳转到新标签页有关问题
- 分享上Google Maps Javascript API v3
- javascript 绑定服务器控件 事件,该如何解决