mirror of
https://github.com/danbulant/discord.js
synced 2026-05-27 22:11:53 +00:00
feat: add Collection#tap (#2507)
* Add Collection#inspect * No u * Rename to tap * Rename variable * Do it here too
This commit is contained in:
parent
ddab8096cf
commit
9f918199d2
1 changed files with 18 additions and 0 deletions
|
|
@ -364,6 +364,24 @@ class Collection extends Map {
|
|||
return accumulator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identical to
|
||||
* [Map.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach),
|
||||
* but returns the collection instead of undefined.
|
||||
* @param {Function} fn Function to execute for each element
|
||||
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||
* @returns {Collection}
|
||||
* @example
|
||||
* collection
|
||||
* .tap(user => console.log(user.username))
|
||||
* .filter(user => user.bot)
|
||||
* .tap(user => console.log(user.username));
|
||||
*/
|
||||
tap(fn, thisArg) {
|
||||
this.forEach(fn, thisArg);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an identical shallow copy of this collection.
|
||||
* @returns {Collection}
|
||||
|
|
|
|||
Loading…
Reference in a new issue