Map.js
2013-12-26 17:49
113 查看
(function() { var Map, map; var __hasProp = Object.prototype.hasOwnProperty; Map = function() { this.entry = {}; this.count = 0; return this; }; Map.prototype.size = function() { return this.count; }; Map.prototype.isEmpty = function() { return this.count === 0; }; Map.prototype.containsKey = function(key) { if (this.isEmpty()) { return false; } return this.entry.hasOwnProperty(key); }; Map.prototype.containsValue = function(val) { var _a, _val, key; if (this.isEmpty()) { return false; } _a = this.entry; for (key in _a) { if (!__hasProp.call(_a, key)) continue; _val = _a[key]; if (_val === val) { return true; } } return false; }; Map.prototype.get = function(key) { if (this.isEmpty()) { return null; } if (this.containsKey(key)) { return this.entry[key]; } return null; }; Map.prototype.put = function(key, val) { if (!this.entry.hasOwnProperty(key)) { this.count += 1; }; this.entry[key] = val; return this; }; Map.prototype.remove = function(key) { if (this.isEmpty()) { return false; } if (this.containsKey(key)) { delete this.entry[key]; this.count -= 1; return true; } return false; }; Map.prototype.putAll = function(map) { var _a, entry, key, val; if (!map instanceof Map) { return false; } entry = map.entry; _a = entry; for (key in _a) { if (!__hasProp.call(_a, key)) continue; val = _a[key]; this.put(key, val); } return true; }; Map.prototype.clear = function() { this.entry = {}; this.count = 0; return this; }; Map.prototype.values = function() { var _a, key, val, vals; vals = []; _a = this.entry; for (key in _a) { if (!__hasProp.call(_a, key)) continue; val = _a[key]; vals.push(val); } return vals; }; Map.prototype.keySet = function() { var _a, key, keys, val; keys = []; _a = this.entry; for (key in _a) { if (!__hasProp.call(_a, key)) continue; val = _a[key]; keys.push(key); } return keys; }; Map.prototype.entrySet = function() { return this.entry; }; Map.prototype.toString = function() { if (typeof JSON === "undefined") { throw new Error("JSON object is not supported. Please check your browser version (IE8+, Firefox11+, Chrome19+, Safari5.1+)."); } return JSON.stringify(this.entry); }; Map.prototype.valueOf = function() { return this.toString(); }; })();
相关文章推荐
- springMVC传递MAP给JS
- 使用JS模拟出Map对象
- js中自定义键值对形式的Map结构
- js里定义map应该怎么写
- js读取json包装的map集合
- js遍历map
- map method in js
- 示例:将通过js获取的json字符串转换为Map、List集合(不太重要)
- js自定义一个Map类
- 使用JS构建简单Map(转)
- js解析json,js转换json成map,获取map的key,value
- jQ基础篇--jQuery与JS中的map()方法
- echarts.js应用之map
- Js笔试题之parseInt()和.map()
- 【javascript】js实现容器Map
- JS中的map、reduce
- JS学习-调用google map API例子
- JS中的forEach、map方法 与 jQuery的$.each方法
- JS构造Map结构
- react.js map遍历的问题