JavaScript HashTable
/**
* ×Ô¼ºµÄ HashTable
* Ô¸½Å±¾ÉñÁ¦ÓëÄãͬÔÚ
*/
function HashTable(){
var values = {};
/** ½«Öµ²åÈë HashTable ÖÐ **/
this.put = function(key, value){
if(key in values){
return false;
}
values[key] = value;
}
/** ¸ù¾Ý key ·µ»Ø value **/
this.find = function(key){
return values[key];
}
/** ¸ù¾Ý key ɾ³ý **/
this.delete = function(key){
if(key in values){
delete values[key];
}
}
/** ½«HashTable ±ä³É String **/
this.toString = function(){
var ins = Array.apply(this,this.toArray(false));
return "{"+ins.toString()+"}";
}
/** ½«HashTable ±ä³É JSON¶ÔÏó **/
this.toJsonObject = function(){
return eval("("+this.toString()+")");
}
/** ½«HashTable ±ä³É Êý×é **/
this.toArray = function(flag){
var valuesArray = [];
var valuesIncludeKey = [];
if(flag){
for(var cur in values){
valuesArray[this.each(cur)] = values[cur];
}
return valuesArray;
}
for(var cur in values){
valuesIncludeKey[this.each(cur)] = cur+":'"+values[cur]+"'";
}
return valuesIncludeKey;
}
this.each = function(key){
var c = 0;
for(var cur in values){
if(cur == key){
return c;
}
c ++;
}
return -1;
}
/** ¸ù¾Ý key ·µ»ØÔÚ HashTable ÖеÄË÷Òý **/
this.indexOf = function(el){
return this.each(el);
}
/** ·´×ª HashTable **/
this.reverse = function(){
return this.toString().split("").reverse().join("");
}
/** ÅжÏHashTable ÊÇ·ñ°üº¬key**/
this.contain = function(key){
return key in values;
}
}
function t(){
var t1 = new HashTable();
t1.put("a","1");
t1.put("b","2");
t1.put("c","3");
t1.put("d","4");
t1.put("e","5");
t1.put("f","6");
t1.put("g","7");
t1.put("h","8");
dwn("find:"+t1.fin
Ïà¹ØÎĵµ£º
×öJava¿ª·¢µÄÈ˶¼ÖªµÀ,ÔÚJavaÖÐÓÐXXXFormat(±ÈÈçSimpleDateFormat)Àà¿ÉÒÔ°ïÖúÎÒÃǵõ½ÏëÒªµÄÊý¾Ý¸ñʽ.ÔÚJavaScriptÖÐûÓÐÕâÑùµÄ¶«Î÷,ËùÒÔÎÒÃÇÐèÒªÓÃÁíÒ»ÖÖ·½·¨µÃµ½ÎÒÃÇÏëÒªµÄ¶«Î÷.´úÂëÈçÏÂ:
<html>
<head>
<title>Test</title>
<mce:script type="text/javascript" language="javascri ......
function unique(data){debugger;
data = data || [];
var a = {};
for (var i=0; i<data.length; i++) {
var v = data[i];
......
Ò». »ù´¡Æª
1. Javascriptѧϰ±Ê¼Ç1——Êý¾ÝÀàÐÍ
2. Javascriptѧϰ±Ê¼Ç2——º¯Êý
3. Javascriptѧϰ±Ê¼Ç3——×÷ÓÃÓò
4. Javascriptѧϰ±Ê¼Ç4——Evalº¯Êý
5. Javascriptѧϰ±Ê¼ ......
JavaScript δ½áÊøµÄ×Ö·û´®³£Á¿
×öJavaScriptµÄʱºò,·¢ÏÖÀÏÊdzöÏÖ´íÎ󣺓δ½áÊøµÄ×Ö·û´®³£Á¿”.
×Ô¼ºÕÒÁËÏÂÓ¦¸ÃÊÇ´«²ÎÊýµÄʱºò,ÓÐÌØÊâ×Ö·ûÒýÆðµÄ.
ÍøÉÏÒ²ÕÒÁËÏÂ,Ò²Óкöà³öÏÖÕâÖÖÇé¿ö.×öÏÂ×ܽá,ÒÔ·½±ãÒÔºó²éÔÄ.
1.JAVASCRIPTÒýÓÃʱ,ʹÓõÄ×Ö·ûÓïÑÔ²»Ò»ÖÂ.
±ÈÈç:<script type=”text/javascrip ......