PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 3== Namepaths ==
 4 
 5When 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.
 6
 7=== Syntax ===
 8{{{
 9myFunction
10MyConstructor
11MyConstructor#instancMember
12MyConstructor.staticMember
13MyConstructor-innerMember
14}}}
15
16=== Example ===
17
18The 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.
19
20{{{
21/** @constructor */
22Person = function() {
23    this.say = function() {
24        return "I'm an instance.";
25    }
26    
27    function say() {
28        return "I'm inner.";
29    }
30}
31Person.say = function() {
32    return "I'm static.";
33}
34
35var p = new Person();
36p.say();      // I'm an instance.
37Person.say(); // I'm static.
38// there is no way to directly access the inner function from here
39}}}
40
41You would use three different namepath syntaxes to refer to the three different methods:
42
43{{{
44Person#say  // the instance method named "say."
45Person.say  // the static method named "say."
46Person-say  // the inner method named "say."
47}}}
48
49You 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.
50
51Note 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:
52
53{{{
54/** @constructor */
55Person = function() {
56    /** @constructor */
57    this.Idea = function() {
58        this.consider = function(){
59            return "hmmm";
60        }
61    }
62}
63
64var p = new Person();
65var i = new p.Idea();
66i.consider();
67}}}
68
69In this case, to refer to the method named "consider," you would use the following namepath:
70
71{{{
72Person#Idea#consider
73}}}
74
75This chaining can be used with any combination of the connecting symbols: # . -