'How do I use JSDoc to document a class-specific callback inside of an ES6 class?
In my JavaScript Tetris clone, the game ends and a "You win" screen displays once the player has cleared a certain number of lines. However, now I want to create a mode where the game ends after some time has passed. In order to do this, I am creating a new class called WinCondition using the ES6 class syntax. The class constructor has a callback argument that checks whether the win condition has been met. I am documenting my code using JSDoc and I want to document the callback inside the class. However, I did not find a way to do this; in fact, what I found was an issue on GitHub explaining that the JSDoc website does not explain how to do this. I've come up with a solution to this problem by documenting my callback as a global callback:
class WinCondition {
/**
* @param {conditionMetCallback} conditionMet A callback function to check whether the win condition has been met
* @param {String} message The message to be displayed when the condition is met
*/
constructor(conditionMet, message) {
/** @type {conditionMetCallback} */
this.conditionMet = conditionMet;
/** @type {String} */
this.message = message;
}
// more method(s) . . .
}
/**
* @callback conditionMetCallback
* @param {GameManager} game The GameManager object associated with the current game
* @param {Object} sceneArgs The scene arguments object used to get information about the current game
* @see GameManager
*/
...but this callback is intended to be class-specific and I would rather not have the documentation be global. Is there a way I can document it as class-specific using the ES6 class syntax?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
