zoukankan      html  css  js  c++  java
  • JS 自己实现Map

       function MyMap() {
            var items = {};
    
            this.has = function (key) {
                return key in items;
            };
            this.set = function (key, value) {
                items[key] = value;
            };
            this.remove = function (key) {
                if (this.has(key)) {
                    delete items[key];
                    return true;
                }
                return false;
            };
            this.get = function (key) {
                return this.has(key) ? items[key] : undefined;
            };
            this.values = function () {
                var values = new Array();
                for (var k in items) {
                    if (this.has(k)) {
                        values.push(items[k]);
                    }
                }
                return values;
            };
            this.getItems = function () {
                return items;
            };
            this.clear = function () {
                items = {};
            };
            this.getCount = function () {
                return Object.keys(items).length;
            };
    
     
        }  
  • 相关阅读:
    ctrl+shift+k取消
    ERROR 1872
    swap
    mysql主从跳过错误
    undo
    gtid
    falcon监控指标
    连接数
    datetime与timestamp相互转换
    截取文件内容
  • 原文地址:https://www.cnblogs.com/gaobing/p/8573342.html
Copyright © 2011-2022 走看看