Documentation: JSDoc Comments

Objective

Students must write comprehensive JSDoc comments documenting functions, classes, and parameters.

Evidence

JSDoc documentation in game components:

  • GameLevelOutside.js - Comprehensive class and method documentation
  • SpriteSheetCoin.js - JSDoc comments on custom class
  • Multiple classes - Parameter and return value documentation

Implementation Details

  • JSDoc block comment syntax (/** … */)
  • @param tags for parameters
  • @returns tags for return values
  • @description for method purposes
  • @example tags for usage examples

Example JSDoc Format

/**
 * SpriteSheetCoin extends the basic Coin class to support image/spritesheet rendering.
 * Instead of a colored circle, you can now display any image asset (gem, star, etc).
 *
 * @example
 * const gemCoin = new SpriteSheetCoin({
 *   id: 'gem-coin',
 *   INIT_POSITION: { x: 0.5, y: 0.5 },
 *   SCALE_FACTOR: 30,
 *   value: 5,
 *   spriteImagePath: '/images/gem.png',
 *   // Optional: if using a spritesheet with multiple frames
 *   spriteFrames: { rows: 2, columns: 2, frameIndex: 0 }
 * }, gameEnv);
 */

Key Concepts

  • JSDoc syntax and tags
  • Parameter and return type documentation
  • IDE integration for JSDoc tooltips
  • Documentation generation with tools
  • Comment coverage metrics