(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中设立不起作用,求解决
- 不走"<script type='text/javascript'>"标签咋回事
- <script type="javascript/text">的有关问题
- 用servlet+jsp+javascript+jdbc做个简单的办公自动化系统流程,该如何解决
- javaScript = == ===区别,该怎么解决
- javascript 怎么验证name=xx.xx的radio表单
- javascript,该怎么处理
- javascript,该如何处理
- javascript 选中文字 但是保存样式 标签
- 新人求问,J2EE方向,html,css,javascript,vml要学到什么程度?解决思路
- javascript 请求servlet兑现将函数中定义的变量作为参数
- javascript 不懂,该如何处理
- javascript 不懂解决方法
- JavaScript 大局函数求实例,高分求
- javaScript 里面 如何知道Object 对象的长度
- javascript 中文本框中数字如何比较
- javascript IE通过,火狐,google浏览器不过解决思路
- Chrome Javascript Click 事件,该如何解决
- javascript 绑定服务器控件 事件,该如何解决
- javascript 经过加密压缩 怎么解压缩
- JavaScript 怎么获取Table中的某个<span> 的值
- javascript 正则表达式 请用小写字母和数目字,首字母必须为字母,长度5-15
- JavaScript 请问一个思路有关问题,当按下鼠标左键,在屏幕上滑动时,会触发什么事件
- javascript 正则Replace,该怎么处理
- javascript 可以实现登录按钮的功能吗?解决办法
- JavaScript 哈希表赋值的有关问题
- JavaScript 除法,希望得到整数解决思路
- 怎么遍历页面中所有div javascript ?
- javascript 函数有关问题