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();
    

      

  • 相关阅读:
    读书笔记第四章
    读书笔记第三章
    读书笔记第二章
    读书笔记第一章
    第十章 读书笔记
    第九章 读书笔记
    第八章读书笔记
    第七章读书笔记
    第六章读书笔记
    第五章读书笔记
  • 原文地址:https://www.cnblogs.com/lemon-zhang/p/7803180.html
Copyright © 2011-2022 走看看