众所周之,js是没有Map类的,要想用还得自己封装一个。
代码如下 | 复制代码 |
(function(win) { var Map = function() { this.count = 0; this.entrySet = {}; }; var proto = Map.prototype; proto.size = function() { proto.isEmpty = function() { proto.containsKey = function(key) { for ( var prop in this.entrySet) { return false; proto.containsValue = function(value) { for ( var key in this.entrySet) { return false; proto.get = function(key) { if (this.containsKey(key)) { return null; proto.put = function(key, value) { proto.remove = function(key) { proto.putAll = function(map) { proto.clear = function() { proto.values = function() { for ( var key in this.entrySet) { return result; proto.keySet = function() { for ( var key in this.entrySet) { return result; proto.toString = function() { return "{" + result.join() + "}"; proto.valueOf = function() { win.Map = Map; |