Leo's Blog

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  13 随笔 :: 3 文章 :: 18 评论 :: 0 Trackbacks
< 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 >
posted on 2006-04-29 20:59 Leo 阅读(449) 评论(2)  编辑  收藏 所属分类: 技术随文

评论

# re: js写的Hashtable类 2006-06-21 11:38 google
不错,leo终于有新作了  回复  更多评论
  

# re: js写的Hashtable类 2006-06-21 13:31 anyang
蹭分,走人!  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: