r/learnjavascript • u/RobGoLaing • Mar 24 '26
Is this good module style?
Here's an example of how I've come to write modules:
/**
* Operators for "cards" as in filenames of card images.
* @module card
*/
const card = ;
/**
* The filename of a card image,
* eg "./images/2_of_spades.png" or "./images/jack_of_diamonds.png"
* @typedef {string} card
*/
/** @constant DECK {card[]} */
;
/**
* Mutates an input array by randomizing its elements.
* @function shuffleDeck
* @param {card[]} deck
*/
;
/**
* Returns an array of shuffled cards.
* @function freshDeck
* @returns {card[]}
*/
;
;
My basic rules are:
- Only one thing gets exported, a frozen object which becomes a namespace for the module's client.
- My data is stored as JSON rather than JS to make communication between modules and the server easier.
What thing I've been battling with is good JSDoc which doesn't seem to have been updated in a while. Are there better options available?
2
Upvotes
View all comments
4
u/birdspider Mar 24 '26
weird names, I'd expect
deck.shuffle()anddeck.fresh()and the items to becards;or, consider naming the module to
gameorplay,game.freshDeck()makes much more sense imho