项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

47 line
1.3 KiB

  1. "use strict";
  2. var MapPolyfill = (function () {
  3. function MapPolyfill() {
  4. this.size = 0;
  5. this._values = [];
  6. this._keys = [];
  7. }
  8. MapPolyfill.prototype.get = function (key) {
  9. var i = this._keys.indexOf(key);
  10. return i === -1 ? undefined : this._values[i];
  11. };
  12. MapPolyfill.prototype.set = function (key, value) {
  13. var i = this._keys.indexOf(key);
  14. if (i === -1) {
  15. this._keys.push(key);
  16. this._values.push(value);
  17. this.size++;
  18. }
  19. else {
  20. this._values[i] = value;
  21. }
  22. return this;
  23. };
  24. MapPolyfill.prototype.delete = function (key) {
  25. var i = this._keys.indexOf(key);
  26. if (i === -1) {
  27. return false;
  28. }
  29. this._values.splice(i, 1);
  30. this._keys.splice(i, 1);
  31. this.size--;
  32. return true;
  33. };
  34. MapPolyfill.prototype.clear = function () {
  35. this._keys.length = 0;
  36. this._values.length = 0;
  37. this.size = 0;
  38. };
  39. MapPolyfill.prototype.forEach = function (cb, thisArg) {
  40. for (var i = 0; i < this.size; i++) {
  41. cb.call(thisArg, this._values[i], this._keys[i]);
  42. }
  43. };
  44. return MapPolyfill;
  45. }());
  46. exports.MapPolyfill = MapPolyfill;
  47. //# sourceMappingURL=MapPolyfill.js.map