Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
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?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda