• js实现hash


    由于项目中用到了hash,自己实现了一个。

    Hash = function () {
        }
        Hash.prototype = {
            constructor: Hash,
            add: function (k, v) {
                if (!this.hasOwnProperty(k)) {
                    this[k] = v;
                }
            },
            remove: function (k) {
                if (this.hasOwnProperty(k)) {
                    delete this[k];
                }
            },
            update: function (k, v) {
                this[k] = v;
            },
            has: function (k) {
                var type = typeof k;
                if (type === 'string' || type === 'number') {
                    return this.hasOwnProperty(k);
                } else if (type === 'function' && this.some(k)) {
                    return true;
                }
                return false;
            },
            clear: function () {
                for (var k in this) {
                    if (this.hasOwnProperty(k)) {
                        delete this[k];
                    }
                }
            },
            empty: function () {
                for (var k in this) {
                    if (this.hasOwnProperty(k)) {
                        return false;
                    }
                }
                return true;
            },
            each: function (fn) {
                for (var k in this) {
                    if (this.hasOwnProperty(k)) {
                        fn.call(this, this[k], k, this);
                    }
                }
            },
            map: function (fn) {
                var hash = new Hash;
                for (var k in this) {
                    if (this.hasOwnProperty(k)) {
                        hash.add(k, fn.call(this, this[k], k, this));
                    }
                }
                return hash;
            },
            filter: function (fn) {
                var hash = new Hash;
                for (var k in this) {
    
                }
            },
            join: function (split) {
                split = split !== undefined ? split : ',';
                var rst = [];
                this.each(function (v) {
                    rst.push(v);
                });
                return rst.join(split);
            },
            every: function (fn) {
                for (var k in this) {
                    if (this.hasOwnProperty(k)) {
                        if (!fn.call(this, this[k], k, this)) {
                            return false;
                        }
                    }
                }
                return true;
            },
            some: function (fn) {
                for (var k in this) {
                    if (this.hasOwnProperty(k)) {
                        if (fn.call(this, this[k], k, this)) {
                            return true;
                        }
                    }
                }
                return false;
            },
            find: function (k) {
                var type = typeof k;
                if (type === 'string' || type === 'number' && this.has(k)) {
                    return this[k];
                } else if (type === 'function') {
                    for (var _k in this) {
                        if (this.hasOwnProperty(_k) && k.call(this, this[_k], _k, this)) {
                            return this[_k];
                        }
                    }
                }
                return null;
            }
        };
  • 相关阅读:
    基金相关知识整理
    Apache Shiro反序列化漏洞复现
    payload分离免杀
    Red Team 工具集之网络钓鱼和水坑攻击
    GPP(Group Policy Preference)组策略偏好漏洞利用
    AdFind
    python爬虫之beautifulsoup的使用
    xargs命令_Linux xargs命令:一个给其他命令传递参数的过滤器
    mutillidae之注册页面的Insert型报错注入
    mutillidae之Insert型注入
  • 原文地址:https://www.cnblogs.com/pigtail/p/3700989.html
Copyright © 2020-2023  润新知