コードコピーは次のとおりです。
<スクリプト言語= "javascript">
関数hashmap(){
/**マップサイズ**/
var size = 0;
/**物体**/
var entry = new object();
/**マップのプット方法**/
this.put = function(key、value){
if(!this.containskey(key)){
サイズ++;
エントリ[key] = value;
}
}
/**マップメソッドを取得**/
this.get = function(key){
this.containskey(key)を返しますか?エントリ[キー]:null;
}
/**マップ削除方法を削除**/
this.remove = function(key){
if(this.containskey(key)&&(delete entry [key])){
サイズ - ;
}
}
/**はキー**/
this.containskey = function(key){
return(入力のキー);
}
/**値が含まれています**/
this.containsvalue = function(value){
for(入力中のvar prop){
if(entry [prop] == value){
trueを返します。
}
}
falseを返します。
}
/**すべての値**/
this.values = function(){
var値= new array();
for(入力中のvar prop){
values.push(entry [prop]);
}
返品値。
}
/**すべてのキー**/
this.keys = function(){
var keys = new Array();
for(入力中のvar prop){
keys.push(prop);
}
キーを返します。
}
/**マップサイズ**/
this.size = function(){
返品サイズ。
}
/** Clear Map **/
this.clear = function(){
サイズ= 0;
entry = new object();
}
}
// HashMapオブジェクトを作成します
var hashmap = new Hashmap();
hashmap.put( "a"、 "1");
hashmap.put( "b"、 "2");
hashmap.put( "a"、 "5");
hashmap.put( "c"、 "3");
hashmap.put( "a"、 "4");
alert(hashmap.size());
</script>