diff --git a/src/common/Extend.ts b/src/common/Extend.ts index b385726..585c47e 100644 --- a/src/common/Extend.ts +++ b/src/common/Extend.ts @@ -861,3 +861,25 @@ Object.defineProperties(Array.prototype, { } }); + +interface Map { + /** + * 只针对V为number的Map, 有值的话, 加上V, 没值则直接set + * V为其他类型时, 直接set + * @param key + * @param value + */ + inc?(key: K, value: V): this; +} + +Object.defineProperties(Map.prototype, { + inc: { + value: function (key: K, value: V) { + if (typeof value == 'number') { + this.set(key, (this.get(key) || 0) + value ); + } else { + this.set(key, value); + } + } + } +});