PageRenderTime 38ms CodeModel.GetById 26ms RepoModel.GetById 2ms app.codeStats 0ms

/wiki/CookBook.wiki

http://jsdoc-toolkit.googlecode.com/
Unknown | 136 lines | 119 code | 17 blank | 0 comment | 0 complexity | 8900ce80cecfd841bb52c2903a12d41b MD5 | raw file
  1. #summary A growing list of code patterns and solutions for documenting them
  2. #labels Draft
  3. = How do I document <some pattern>? =
  4. == Prototype Library-Based Classes ==
  5. === Class Pattern ===
  6. {{{
  7. var MyClass = Class.create(
  8. /** @lends MyClass# */
  9. {
  10. /**
  11. * Description of constructor.
  12. * @class Description of class.
  13. * @constructs
  14. */
  15. initialize: function(arg0, arg1) {
  16. //...
  17. },
  18. /** A method. */
  19. myFunc: function() {},
  20. /** An instance field. */
  21. myVar: 123
  22. }
  23. );
  24. // ... and if you want to add class fields ...
  25. Object.extend(MyClass,
  26. /** @lends MyClass */
  27. {
  28. /** A class method. */
  29. classFunc: function() {}
  30. }
  31. );
  32. }}}
  33. === Sub-class Pattern ===
  34. {{{
  35. /**
  36. * @class
  37. */
  38. var MySuper = Class.create(
  39. /** @lends MySuper.prototype */
  40. {
  41. /** A method of the superclass. */
  42. superMethod: function() {
  43. // ...
  44. }
  45. });
  46. /**
  47. * Class description
  48. * @class
  49. * @augments MySuper
  50. */
  51. var MyClass = Class.create(MySuper,
  52. /** @lends MyClass# */
  53. {
  54. /** A method of the subclass. */
  55. myMethod: function() {
  56. // ...
  57. }
  58. }
  59. );
  60. }}}
  61. === Mixin Pattern ===
  62. {{{
  63. // Here's how to define a mixin API
  64. /**
  65. * Document Observable class here
  66. * @class
  67. */
  68. var Observable =
  69. /**
  70. * This is an API that can be mixed into other objects
  71. * @lends Observable#
  72. */
  73. {
  74. observe: function(callback) {
  75. //...
  76. },
  77. notify: function(event) {
  78. //...
  79. }
  80. };
  81. // Now let's mix the API into a class ...
  82. /**
  83. * MyClass.prototype gets the Observable API
  84. * @class
  85. * @borrows Observable#observe as #observe
  86. * @borrows Observable#notify as #notify
  87. */
  88. var MyClass = function() {
  89. //...
  90. }
  91. MyClass.addMethods(Observable);
  92. }}}
  93. === Extends Pattern ===
  94. This is similar to the Mixin pattern, except it operates on individual instances of objects, not classes
  95. {{{
  96. var Slideable =
  97. /** @lends Slideable */
  98. {
  99. /**
  100. @class API for enabling a "slide" effect on a DOM element
  101. @constructs
  102. */
  103. extend: function(anElement) {
  104. Object.extend(anElement, this._methods);
  105. },
  106. _methods:
  107. /** @lends Slideable# */
  108. {
  109. /** Start the slide. */
  110. startSlide: function() {
  111. },
  112. /** Stop the slide. */
  113. stopSlide: function() {
  114. },
  115. }
  116. }
  117. // Now Make an element slideable
  118. Slideable.extend(document.getElementById('slider'));
  119. }}}