hashtableobj.set("length","0") 버그 수정 대소문자를 무시하도록 키를 설정할 수 있습니다해시테이블 개체를 복제할 수 있습니다obj.valueOf("key","를 사용할 수 있습니다. defalutvalue")를 기본값으로 설정합니다. Wait버그 수정을 환영합니다 코드 복사 코드는 다음과 같습니다. <머리> <br>// 작성자 Birdshome, 麻袋@博客园 改版 phito,彭海涛 <br>Object.prototype.Clone = function() <br>{ <br>var objClone; <br>if ( this.constructor == Object ) objClone = new this.constructor(); <br>else objClone = new this.constructor(this.valueOf()); <br>for ( var key in this ) <br>{ <br>if ( objClone[key] != this[key] ) <br>{ <br>if ( typeof(this[key]) == 'object ' ) <br>{ <br>objClone[key] = this[key].Clone(); <br>} <br>else <br>{ <br>objClone[key] = this[key]; <br>} <br>} <br>} <br>objClone.toString = this.toString; <br>objClone.valueOf = this.valueOf; <br>objClone을 반환합니다. <br>} <br>function Hashtable() { <br>this.clear = hashtable_clear; <br>this.containsKey = hashtable_containsKey; <br>this.containsValue = hashtable_containsValue; <br>this.get = hashtable_get; <br>this.isEmpty = hashtable_isEmpty; <br>this.keys = hashtable_keys; <br>this.put = hashtable_put; <br>this.remove = hashtable_remove; <br>this.size = hashtable_size; <br>this.toString = hashtable_toString; <br>this.values = hashtable_values; <br>this.hashtable = new Object(); <br>this.set = hashtable_set; <br>this.valueOf = hashtable_valueOf; <br>this.clone = hashtable_clone; <br>this.ignoreupperlower = true; <br>//是否忽略大小写 <br>} <br>/*=======내부 전용 개인 메소드========*/ <br>function hashtable_clone(){ <br>return this.Clone(); <br>} <br>function hashtable_put(key, value) { <br>if (this.ignoreupperlower && typeof(key) == "string") { <br>key = key.toUpperCase(); <br>} <br>if (key == null || value == null) { <br>throw "NullPointerException {" key "},{" value "}"; <br>} else { <br>this.hashtable[키] = 값; <br>} <br>} <br>function hashtable_set(key, value) { <br>if (this.ignoreupperlower && typeof(key) == "string") { <br>key = key.toUpperCase(); <br>} <br>if (this.containsKey(key)) { <br>this.remove(key); <br>} <br>this.put(키, 값); <br>} <br>function hashtable_get(key) { <br>if (this.ignoreupperlower && typeof(key) == "string") { <br>key = key.toUpperCase(); <br>} <br>return this.hashtable[key]; <br>} <br>function hashtable_valueOf(key, defvalue) { <br>var ret = this.get(key); <br>if (typeof(ret) == "정의되지 않음") { <br>기본값 반환; <br>} <br>return ret; <br>} <br>function hashtable_remove(key) { <br>if (this.containsKey(key)) { <br>delete this.hashtable[key] ; <br>} <br>} <br>function hashtable_isEmpty() { <br>return (parseInt(this.size()) == 0) ? 참: 거짓; <br>} <br>function hashtable_size() { <br>var size = 0; <br>for (var i in this.hashtable) { <br>if(typeof(this.hashtable[i])=="function"){ <br>계속; <br>} <br>if (this.hashtable[i] != null) { <br>크기 ; <br>} <br>} <br>반환 크기; <br>} <br>function hashtable_toString() { <br>var result = ""; <br>for (var i in this.hashtable) { <br>if(typeof(this.hashtable[i])=="function"){ <br>계속; <br>} <br>if (this.hashtable[i] != null) { <br>result = "{" i ":" this.hashtable[i] "}n"; <br>} <br>} <br>결과 반환; <br>} <br>function hashtable_clear() { <br>this.hashtable = new Object(); <br>} <br>function hashtable_containsKey(key) { <br>if (this.ignoreupperlower && typeof(key) == "string") { <br>key = key.toUpperCase(); <br>} <br>var 존재 = false; <br>for (var i in this.hashtable) { <br>if(typeof(this.hashtable[i])=="function"){ <br>계속; <br>} <br>if (i == key && this.hashtable[i] != null) { <br>exists = true; <br>휴식; <br>} <br>} <br>반품이 존재합니다. <br>} <br>function hashtable_containsValue(value) { <br>var contain = false; <br>if (value != null) { <br>for (var i in this.hashtable) { <br>if(typeof(this.hashtable[i])=="function"){ <br>continue; <br>} <br>if (this.hashtable[i] == value) { <br>contains = true; <br>휴식; <br>} <br>} <br>} <br>반환 내용: <br>} <br>function hashtable_values() { <br>var value = new Object(); <br>for (var i in this.hashtable) { <br>if(typeof(this.hashtable[i])=="function"){ <br>계속; <br>} <br>if (this.hashtable[i] != null) value.push(this.hashtable[i]); <br>} <br>반환 값; <br>} <br>function hashtable_keys() { <br>varkeys = new Object(); <br>for (var i in this.hashtable) { <br>if(typeof(this.hashtable[i])=="function"){ <br>계속; <br>} <br>keys.push(i); <br>} <br>반환 키; <br>} <br>function test() { <br>var ht = new Hashtable(); <br>ht.put("3", "잭슨"); <br>ht.put("2", "톰"); <br>ht.put("4", 3); <br>ht.set("길이", 445555); <br>ht.set("ddd", "ddd"); <br>ht.set("index", "ddd"); <br>var et = ht.toString(); <br>ht.ignoreupperlower = false; <br>//忽略大小写 <br>ht.clear(); <br>ht.put("3", "잭슨"); <br>ht.put("2", "톰"); <br>ht.remove("2"); <br>ht.put("4", 3); <br>ht.set("길이", 5); <br>//사용할 수 있는 새로운 어레이의 설명 <br>ht.set("index", "ddd"); <br>ht.set("ddd", "ddd"); <br>alert(et "" ht.toString() "" ht.size()); <br>var cloneobj=ht.clone(); <br>alert(cloneobj.toString()); <br>}<br> 더 나은 기능을 갖춘 해시테이블과 해시셋을 사용하고 싶다면 http://xiazai.jb51.net/201012/yuanma/jshashtable.rar를 다운로드하세요.