IT-攻城师 发表于 2013-1-29 08:53:50

javascript 虚拟创建HashMap对象

 
/******************************************************************************* * 虚拟创建HashMap对象 * @author DT 2011-12-17 * @version 1.0 ** 说明: * HashMap有两个Array数组构成 分别保存key、value * 场景: * 数据封装、解析 ********************************************************************************/function HashMap() {this.arrKey = new Array();this.arrValue = new Array();this.exists = function(strKey) {strKey = strKey.toUpperCase();for (var i = 0;i < this.arrKey.length; i++) {if (this.arrKey == strKey) {return true;}}return false;};this.length = function() {return this.arrKey.length;};this.put = function(strKey, objValue) {strKey = strKey.toUpperCase();for (var i = 0;i < this.arrKey.length; i++) {if (this.arrKey == strKey) {this.arrValue = objValue;return;}}this.arrKey = strKey;this.arrValue = objValue;};this.get = function(strKey) {strKey = strKey.toUpperCase();for (var i = 0;i < this.arrKey.length; i++) {if (this.arrKey == strKey) {return this.arrValue;}}return null;};this.remove = function(strKey) {strKey = strKey.toUpperCase();for (var i = 0;i < this.arrKey.length; i++) {if (this.arrKey == strKey) {this.arrKey.splice(i, 1);this.arrValue.splice(i, 1);return;}}};this.getKeys = function() {return this.arrKey;};this.getValues = function() {return this.arrValue;};} 
页: [1]
查看完整版本: javascript 虚拟创建HashMap对象