zoukankan      html  css  js  c++  java
  • Dictionary of js

    function Dictionary() {
        this.datastore = new Array();
    };
    Dictionary.prototype = {
        constructor: Dictionary,
        add: function(key, value) {
            this.datastore[key] = value;
        },
        find: function(key) {
            return this.datastore[key];
        },
        remove: function(key) {
            delete this.datastore[key];
        },
        showAll: function() {
            var _this = this;
            Object.keys(this.datastore).sort().forEach(function(val, key) {
                console.log(val + " -> " + _this.datastore[val]);
            });
        },
        count: function() {
            var n = 0;
            Object.keys(this.datastore).forEach(function(val, key) {
                ++n;
            });
            return n;
        },
        clear: function() {
            var _this = this;
            Object.keys(this.datastore).forEach(function(val, key) {
                 delete _this.datastore[val];
            });
        }
    };
    var telephoneBook = new Dictionary();
    telephoneBook.add('Tom', 13713750081);
    telephoneBook.add('Bom', 13713550081);
    telephoneBook.add('Cindy', 43713750081);
    telephoneBook.showAll();
    

      

  • 相关阅读:
    Skimage=scikit-image SciKit 包的模块(转载)
    python day12
    python day11
    python day10
    python day9
    python day8
    python day7
    python day6
    python 第五天
    python 第四天
  • 原文地址:https://www.cnblogs.com/lemon-zhang/p/7803180.html
Copyright © 2011-2022 走看看