码迷,mamicode.com
首页 > Web开发 > 详细

Dictionary of js

时间:2017-11-08 13:08:31      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:tor   for   bom   tom   div   cin   show   highlight   count   

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

  

Dictionary of js

标签:tor   for   bom   tom   div   cin   show   highlight   count   

原文地址:http://www.cnblogs.com/lemon-zhang/p/7803180.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!