diff --git a/src/util/Collection.js b/src/util/Collection.js index 13ab31cc3b23..36d13fdd3cca 100644 --- a/src/util/Collection.js +++ b/src/util/Collection.js @@ -319,6 +319,15 @@ class Collection extends Map { return accumulator; } + /** + * Creates an identical shallow copy of this collection. + * @returns {Collection} + * @example const newColl = someColl.clone(); + */ + clone() { + return new this.constructor(this); + } + /** * Combines this collection with others into a new collection. None of the source collections are modified. * @param {...Collection} collections Collections to merge @@ -326,8 +335,7 @@ class Collection extends Map { * @example const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl); */ concat(...collections) { - const newColl = new this.constructor(); - for (const [key, val] of this) newColl.set(key, val); + const newColl = this.clone(); for (const coll of collections) { for (const [key, val] of coll) newColl.set(key, val); }