简体   繁体   中英

Discord.js / JS What is the difference here

What is the difference between a Map :

let collection = new Map()

And a discord.js Collection :

let collection = new Discord.Collection()

Or both are basically the same?

It's described in Discord's docs :

Discord.js comes with this utility class known as Collection. It extends JavaScript's native Map class, so it has all the features of Map and more!

In essence, Map allow for an association between unique keys and their values, but lack an iterative interface. For example, how can you transform every value or filter the entries in a Map easily? This is the point of the Collection class!

Discord collections are Maps that also have:

  • Certain array prototype methods like .find , .filter , .every
  • .array() (converts the collection to an array)
  • Various other utility methods like .random() (gives a random value), .first() (gives the first value), .last() (gives the last value), .sweep (removes all values from the collection that fail the callback). See the docs for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM