zoukankan      html  css  js  c++  java
  • javascript仿es6的map类

     var Dictionary = (function (){
            var f = function(){
                this._items = {};
            };
            var proto = f.prototype;
            proto.has = function(key){
                return key in this._items;
            }
            proto.set = function(key,value){
                this._items[key] = value;
            }
            proto.remove = function(key){
                if(this.has(key)){
                    delete this._items[key];
                    return true;
                }
                return false;
            }
            proto.get = function(key){
                return this.has(key) ? this._items[key] : undefined;
            };
            proto.values  = function (){
                var values = [];
                for(var k in this._items){
                    if(this.hsa(k)){
                        values.push(this._items[k]);
                    }
                }
                return values;
            };
            proto.clear = function(){
                this._items = {};
            };
            proto.size = function(){
                var count = 0;
                for(var prop in this._items){
                    if(this._items.hasOwnProperty(prop)){
                         ++ count;
                    }
                }
                return count;
            };
            proto.keys = function(){
                var keys = [];
                for(var prop in this._items){
                    if(this._items.hasOwnProperty(prop)){
                        keys.push(prop);
                    }
                }
                return keys;
            };
            proto.getItems = function(){
                return this._items;
            }
            return f;
        })();
  • 相关阅读:
    安装django(使用国内镜像)
    adb工具安装与配置
    mysql
    Charles抓包(iOS的http/https请求)
    selenium+python第一个自动化脚本
    selenium+python环境搭建
    python,你好!
    tjkd-html
    asp
    uglifyjs压缩批处理
  • 原文地址:https://www.cnblogs.com/kerryw/p/8630881.html
Copyright © 2011-2022 走看看