JavaScript中的简单哈希表(关联数组)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript中的简单哈希表(关联数组)相关的知识,希望对你有一定的参考价值。
/* --==[ EXAMPLE ]==--var colors = new AArray();
colors.add("k01", {bk:"#fff",tk:"b",it:"hello"});
var oC = colors.get("k01");
var tT = '';
for(K in oC) tT += "[" + K + "]: " + oC[K] + " ";
tT += " ";
tT += oC.bk + " ";
tT += oC.tk + " ";
tT += oC.it + " ";
alert(tT);
*/
var Class = { create: function() { return function() { this.initialize.apply(this, arguments); } } } var AArray = Class.create(); AArray.prototype = { AA: {}, initialize: function() { args = this.initialize.arguments; if(args.length > 0) { this.add(args[0], args[1]); } }, add: function(key, value) { this.AA[key] = value; }, num: function() { return this.AA.length; }, get: function(key) { return this.AA[key]; }, set: function(key, value) { this.add(key, value); }, test: function() { var aa = ''; var num = this.num(); for(key in this.AA) aa += '[' + key + ']: ' + this.AA[key] + " "; alert(aa); } }
以上是关于JavaScript中的简单哈希表(关联数组)的主要内容,如果未能解决你的问题,请参考以下文章