码迷,mamicode.com
首页 > Web开发 > 详细

JS 自定义字典对象

时间:2014-07-22 23:08:35      阅读:1053      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   使用   

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

JS 自定义字典对象

标签:style   blog   http   java   color   使用   

原文地址:http://www.cnblogs.com/wzq806341010/p/3700413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!