7.6 Class comments

Classes, interfaces and records must be documented with a description and anytemplate parameters, implemented interfaces, visibility, or other appropriatetags. The class description should provide the reader with enough information toknow how and when to use the class, as well as any additional considerationsnecessary to correctly use the class. Textual descriptions may be omitted on theconstructor. @constructor and @extends annotations are not used with theclass keyword unless the class is being used to declare an @interface orit extends a generic class.

  1. /**
  2. * A fancier event target that does cool things.
  3. * @implements {Iterable<string>}
  4. */
  5. class MyFancyTarget extends EventTarget {
  6. /**
  7. * @param {string} arg1 An argument that makes this more interesting.
  8. * @param {!Array<number>} arg2 List of numbers to be processed.
  9. */
  10. constructor(arg1, arg2) {
  11. // ...
  12. }
  13. };
  14. /**
  15. * Records are also helpful.
  16. * @extends {Iterator<TYPE>}
  17. * @record
  18. * @template TYPE
  19. */
  20. class Listable {
  21. /** @return {TYPE} The next item in line to be returned. */
  22. next() {}
  23. }