JS 自定义字典对象

时间:2014-07-22 23:08:35   收藏:0   阅读:1053
mamicode.com,码迷
  <script type="text/javascript" language="javascript">
//自定义字典对象
function Dictionary(){
 this.data ={};
 
 this.put = function(key,value){
  this.data[key] = value;
 };

 this.get = function(key){
  return this.data[key];
 };

 this.remove = function(key){
  this.data[key] = null;
 };
 
 this.isEmpty = function(){
  return this.data.length == 0;
 };

 this.size = function(){
  return this.data.length;
 };
}

//使用 例子
var d = new Dictionary();
d.put("CN",{id:1,name:‘df‘});
d.put("US", "America");
document.write(d.get("CN").name);
document.write(d.get("US"));


var dic={};
dic.a=1;
dic["b"]={id:1,name:"wqeqweqwewqe"}
function get(key){
    return dic[key];
}
document.write(get("b").name);
</script>
mamicode.com,码迷

 

JS 自定义字典对象,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!