zoukankan      html  css  js  c++  java
  • jquery哈希表

    jQuery.Hashtable = function () {
        
    this.items = new Array();
        
    this.itemsCount = 0;
        
    this.add = function (key, value) {
            
    if (!this.containsKey(key)) {
                
    this.items[key] = value;
                
    this.itemsCount++;
            }
            
    else {
                
    //throw "key '" + key + "' allready exists."
                this.items[key] = value;
            }
        }

        
    this.get = function (key) {
            
    if (this.containsKey(key))
                
    return this.items[key];
            
    else
                
    return null;
        }

        
    this.remove = function (key) {
            
    if (this.containsKey(key)) {
                delete 
    this.items[key];
                
    this.itemsCount--;
            }
            
    else
                
    throw "key '" + key + "' does not exists."

        }

        
    this.containsKey = function (key) {
            
    return typeof (this.items[key]) != "undefined";
        }

        
    this.containsValue = function containsValue(value) {
            
    for (var item in this.items) {
                
    if (this.items[item] == value)
                    
    return true;
            }

            
    return false;
        }

        
    this.contains = function (keyOrValue) {
            
    return this.containsKey(keyOrValue) || this.containsValue(keyOrValue);
        }

        
    this.clear = function () {
            
    this.items = new Array();
            itemsCount 
    = 0;
        }

        
    this.size = function () {
            
    return this.itemsCount;
        }

        
    this.isEmpty = function () {
            
    return this.size() == 0;
        }
    };

    使用方法:

    var hashtable = new jQuery.Hashtable(); 
            hashtable.add(
    "hello",["world","hello world"]);
            hashtable.add(
    "aaa",["111","3333"]);
            alert(hashtable.get(
    "aaa")[1]);


     

  • 相关阅读:
    stylus 安装
    Vue中img的src属性绑定与static文件夹
    vue-cli的build的文件夹下没有dev-server.js文件,怎么配置mock数据
    easyui中的datebox空间,起始时间不受限制,终止时间不能选择起始时间选中的时间靠前的时间
    python实现文件下载图片视频
    python爬虫 urllib库基本使用
    python面向对象的三大特征
    常见网页状态码
    说说为什么会有ssl.CertificateError报错
    python-魔术方法
  • 原文地址:https://www.cnblogs.com/timy/p/1986039.html
Copyright © 2011-2022 走看看