也不是我原创的,不过是我注释的,很好用的一个HashTable //转定义 相当与c++ typedefvar _UNDEFINED_="undefined";//HashTable对象function Hashtable() ...{ this.count=0; this.content= new Object(); //判断是否定义 this.defined=function(p) ...{ return typeof(p)!=_UNDEFINED_; } //添加HashTable 键值 this.add = function(key,value) ...{ if(this.contains(key)) return false; //如果该关键字已经存在 this.content[key]=value; //设置键值 this.count++; //增加表长度 return true; } //移除HashTable 键值 this.remove= function(key) ...{ if(!this.contains(key)) return; //如果该关键字不存在 delete this.content[key]; //清空数据 this.count--; //表长度减1 } //得到HashTable 键值 this.items = function(key) ...{ if(this.contains(key)) return this.content[key]; //如果关键字存在 返回键值 return null; } //判断是否存在 this.contains= function(key) ...{ return this.defined(this.content[key]); //判断是否已经定义 } //清空HashTable this.clear= function() ...{ for(var k in this.content) delete this.content[k]; //遍历所有 键值 并清空数据 this.count=0; //重置表长度 } //对象转字符串 this.toString=function() ...{ var sb=new StringBuilder(); //字符串处理对象 var hasItem=false; //是否为第一键值 for(var k in this.content) //遍历所有 键值 ...{ if(hasItem) sb.appendFormat("&{0}={1}",k,this.content[k]); //字符串化 else ...{ sb.appendFormat("{0}={1}",k,this.content[k]); hasItem=true; } } return sb.toString(); }}