zoukankan      html  css  js  c++  java
  • js插件-Map插件

    自己封装的jsMap插件,虽然很小,但是基本实现了功能。

    /**
     * Map
     */
    (function(){
    	function jMap(){
    		//私有变量
    		var arr = {};
    		//增加
    		this.put = function(key,value){
    			arr[key] = value;
    		}
    		//查询
    		this.get = function(key){
    			if(arr[key]){
    				return arr[key]
    			}else{
    				return null;
    			}
    		}
    		//删除
    		this.remove = function(key){
    			//delete 是javascript中关键字 作用是删除类中的一些属性
    			delete arr[key]
    		}
    		//遍历
    		this.eachMap = function(fn){
    			for(var key in arr){
    				fn(key,arr[key])
    			}
    		}
    	}
    	var country = new jMap();
    	country.put("01","ZG");
    	country.put("02","HG");
    	country.put("03","MG");
    	country.put("04","TG");
    	//alert(country.get("01"))
    	country.remove("01")
    	//alert(country.get("01"))
    	
    	country.eachMap(function(key,value){
    		document.write(key+"-->"+value+"<br>");
    	})
    })()
    


  • 相关阅读:
    hdoj 1872 稳定排序
    nyoj 60 谁获得了最高奖学金
    hdoj 2066 一个人的旅行
    nyoj 8 一种排序
    bzoj1798 1
    bzoj4031
    SPOJ-HIGH
    学习笔记::矩阵树定理
    学习笔记::树上莫队
    Strip
  • 原文地址:https://www.cnblogs.com/sunyingyuan/p/3686217.html
Copyright © 2011-2022 走看看