zoukankan      html  css  js  c++  java
  • JS模拟Dictionary

    function Map() {
        this.keys = new Array();
        this.data = new Array();
        //添加键值对
        this.set = function (key, value) {
            if (this.data[key] == null) {//如键不存在则身【键】数组添加键名
                this.keys.push(key);
            }
            this.data[key] = value;//给键赋值
        };
        //获取键对应的值
        this.get = function (key) {
            return this.data[key];
        };
        //去除键值,(去除键数据中的键名及对应的值)
        this.remove = function (key) {
            this.keys.remove(key);
            this.data[key] = null;
        };
        //判断键值元素是否为空
        this.isEmpty = function () {
            return this.keys.length == 0;
        };
        //获取键值元素大小
        this.size = function () {
            return this.keys.length;
        };
        this.ContainsKey = function (key) {
            if (this.data[key] == null) {//如键不存在则身【键】数组添加键名
                return false;
            }
            else {
                return true;
            }
        }
    }
  • 相关阅读:
    position中的四种属性
    CSS中link和@import的区别
    隐藏对应元素的办法
    word20161217
    word20161216
    word20161215
    word20161214
    word20161213
    word201612012
    word20161211
  • 原文地址:https://www.cnblogs.com/wanren/p/3599492.html
Copyright © 2011-2022 走看看