js 封装map 对象

var Map = function() {
  this.keys = new Array,
  this.data = new Object;
  var e = Object.prototype.toString;
  this.size = function() {
      return this.keys.length
  },
  this.put = function(e, t) {
      this.data[e] == null && (this.data[e] = t),
      this.keys.push(e)
  },
  this.get = function(e) {
      return this.data[e]
  },
  this.set = function(e, t) {
      this.data[e] = t
  },
  this.remove = function(e) {
      var t = this.indexOf(e);
      t != -1 && this.keys.splice(t, 1),
      this.data[e] = null
  },
  this.clear = function() {
      for (var e = 0,
      t = this.size(); e < t; e++) {
          var n = this.keys[e];
          this.data[n] = null
      }
      this.keys.length = 0
  },
  this.containsKey = function(e) {
      return this.data[e] != null
  },
  this.isEmpty = function() {
      return this.keys.length === 0
  },
  this.entrySet = function() {
      var e = this.size(),
      t = new Array(e);
      for (var n = 0,
      r = e; n < r; n++) {
          var i = this.keys[n],
          s = this.data[i];
          t[n] = {
              key: i,
              value: s
          }
      }
      return t
  },
  this.each = function(t) {
      if (e.call(t) === "[object Function]") for (var n = 0,
      r = this.size(); n < r; n++) {
          var i = this.keys[n];
          t(n, i, this.data[i])
      }
      return null
  },
  this.indexOf = function(e) {
      var t = this.size();
      if (t > 0) for (var n = 0,
      r = t; n < r; n++) if (this.keys[n] == e) return n;
      return - 1
  },
  this.toString = function() {
      var e = "{";
      for (var t = 0,
      n = this.size(); t < n; t++, e += ",") {
          var r = this.keys[t],
          i = this.data[r];
          e += r + "=" + i
      }
      return e = e.substring(0, e.length - 1),
      e += "}",
      e
  },
  this.values = function() {
      var e = this.size(),
      t = new Array(e);
      for (var n = 0; n < e; n++) {
          var r = this.keys[n];
          t.push(this.data[r]);
      }
      return t;
  }
};

Q.E.D.