mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Add Collection.clone() (#1238)
* Add Collection.clone() * More efficient cloning, and concat update * Update Collection.js * Update Collection.js
This commit is contained in:
committed by
Schuyler Cebulskie
parent
01d8d32ea9
commit
25bb602d5a
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user