/wiki/NamePaths.wiki

http://jsdoc-toolkit.googlecode.com/ · Unknown · 75 lines · 58 code · 17 blank · 0 comment · 0 complexity · 25b3e8aeedcf13b87002ba35b3d23deb MD5 · raw file

  1. #summary Using namepaths to refer to symbols.
  2. == Namepaths ==
  3. When referring to a !JavaScript variable that is elsewhere in your documentation, you must provide a unique identifier that maps to that variable. A namepath provides a way to do so and disambiguate between instance members, static members and inner variables.
  4. === Syntax ===
  5. {{{
  6. myFunction
  7. MyConstructor
  8. MyConstructor#instancMember
  9. MyConstructor.staticMember
  10. MyConstructor-innerMember
  11. }}}
  12. === Example ===
  13. The example below shows: an _instance_ method named "say," an _inner_ function also named "say," and a _static_ method also named "say." These are three distinct methods that all exist independently of one another.
  14. {{{
  15. /** @constructor */
  16. Person = function() {
  17. this.say = function() {
  18. return "I'm an instance.";
  19. }
  20. function say() {
  21. return "I'm inner.";
  22. }
  23. }
  24. Person.say = function() {
  25. return "I'm static.";
  26. }
  27. var p = new Person();
  28. p.say(); // I'm an instance.
  29. Person.say(); // I'm static.
  30. // there is no way to directly access the inner function from here
  31. }}}
  32. You would use three different namepath syntaxes to refer to the three different methods:
  33. {{{
  34. Person#say // the instance method named "say."
  35. Person.say // the static method named "say."
  36. Person-say // the inner method named "say."
  37. }}}
  38. You might wonder why there is a syntax to refer to an inner method when that method isn't directly accessible from outside the function it is defined in. While that is true, and thus the "-" syntax is rarely used, it _is_ possible to return a reference to an inner method from another method inside that container, so it is possible that some object elsewhere in your code might borrow an inner method.
  39. Note that if a constructor has an instance member that is also a constructor, you can simply chain the namepaths together to form a longer namepath:
  40. {{{
  41. /** @constructor */
  42. Person = function() {
  43. /** @constructor */
  44. this.Idea = function() {
  45. this.consider = function(){
  46. return "hmmm";
  47. }
  48. }
  49. }
  50. var p = new Person();
  51. var i = new p.Idea();
  52. i.consider();
  53. }}}
  54. In this case, to refer to the method named "consider," you would use the following namepath:
  55. {{{
  56. Person#Idea#consider
  57. }}}
  58. This chaining can be used with any combination of the connecting symbols: # . -