☆蓝色梦想☆

世界总是反反覆覆错错落落地飘去 来不及叹息 生活不是平平淡淡从从容容的东西 不能放弃
posts - 57, comments - 5, trackbacks - 0, articles - 0

js写的Hashtable类

Posted on 2006-08-16 23:22 ☆蓝色梦想☆ 阅读(260) 评论(0)  编辑  收藏 所属分类: AJAX
< 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 >

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


网站导航: