当前位置:IT168首页 > 技术开发 > 概述
[收藏此页] [打印] [推荐] [评论]

JavaScript之HashTable

责任编辑:nancy作者:ITPUB论坛   2008-07-11   
文本Tag: 微软 sql

【IT168技术文档】

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JSHashTable</title> <script type=text/javascript> function HashTable() { this.__hash = {}; this.Add = function(key,value) { if(typeof(key) != "undefined") { //if it not contains in hashtable if(! this.contains(key)) { this.__hash[key] = typeof(value) == "undefined" ? null : value; return true; } else{ return false; } } }; this.Remove = function(key){ delete this.__hash[key]; }; this.count = function(){ var i = 0; for(var obj 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 obj in this.__hash) { delete this.__hash[k]; } }; } var obj = new HashTable(); obj.Add("a"); obj.Add("b","b"); obj.Add("a"); obj.Remove("a"); alert(obj.contains("a")); obj.Add("c","I love you"); alert(obj.items("c")); </script> </head> <body> </body> </html>
上一页
1
下一页
收藏到: 添加到“百度搜藏”添加到“QQ书签”添加到“Google书签”添加到“Yahoo收藏”添加到“和讯网摘”
【内容导航】
本文欢迎转载,转载请注明:转载自IT168 [ http://www.it168.com/ ]
本文链接:http://tech.it168.com/d/2008-07-11/200807111232409.shtml
技术开发相关文章  
  • 暂无
友情推介