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;
        })();
  • 相关阅读:
    内存可用性判断 IsBadCodePtr IsBadReadPtr 等等
    部署到Linux使用VS Code 开发.NET Core 应用程序
    Gulp.js简介
    net WebApi中使用swagger
    深入理解
    软件框架
    重拾linux
    Linux创建修改删除用户和组
    Linux 之 rsyslog
    Lua 解释器
  • 原文地址:https://www.cnblogs.com/kerryw/p/8630881.html
Copyright © 2011-2022 走看看