Chinaunix首页 | 论坛 | 博客
  • 博客访问: 284083
  • 博文数量: 82
  • 博客积分: 2607
  • 博客等级: 少校
  • 技术积分: 785
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-14 15:23
文章分类

全部博文(82)

文章存档

2012年(4)

2010年(1)

2009年(2)

2008年(8)

2007年(34)

2006年(33)

我的朋友

分类: Java

2006-09-14 16:12:11

<script language="javascript" type="text/javascript">

function Hashtable()
{
    
this._hash      = new Object();
    
this.add        = function(key,value){
                        
if(typeof(key)!="undefined"){
                            
if(this.contains(key)==false){
                                
this._hash[key]=typeof(value)=="undefined"?null:value;
                                
return true;
                            } 
else {
                                
return false;
                            }
                        } 
else {
                            
return false;
                        }
                    }
    
this.remove        = function(key){delete this._hash[key];}
    
this.count        = function(){var i=0;for(var k in this._hash){i++;} return i;}
    
this.items        = function(key){return this._hash[key];}
    
this.contains    = function(key){ return typeof(this._hash[key])!="undefined";}
    
this.clear        = function(){for(var k in this._hash){delete this._hash[k];}}

}

var a = new Hashtable();

a.add(
"aa");
a.add(
"bb",2342);
a.add(
"bb",2342);

a.remove(
"aa");

alert(a.count());

alert(a.contains(
"bb"));

alert(a.contains(
"aa"));

alert(a.items(
"bb"));


script>
阅读(789) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~