Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is in reply to the comments to <a href="https://stackoverflow.com/questions/2564032/writing-a-javascript-library-that-is-code-completion-and-code-inspection-friendly#answer-2564608">mwilcox's post</a>.</p> <p>That example will actually work. Since <code>myLibrary</code> is defined without <code>var</code>, it is automatically put into the global namespace and accessible as such. Through the closure created by the self-executing function, the private variables and methods are still accessible in the <code>myLibrary</code> methods. You can easily try this out by putting it into Firebug or Rhino.</p> <p>These days, I do not tend to hide my variables, i.e. I use the Pseudoclassical pattern or the Prototypal pattern and prefix my <em>intended</em> private methods with an <code>_</code>:</p> <pre><code>// Pseudoclassical pattern function Hello() {} Hello.prototype = { method1: function() {}, method2: function() {}, _pseudeoPrivate: function() {} }; /* Prototypal pattern. To create multiple instances of this object, you need a helper function such as function beget(o) { var F = function() {}; F.prototype = o; return new F; } var instance = beget(world); */ var world = { method1: function() {}, method2: function() {} }; </code></pre> <p>To prevent my code from polluting the global namespace, I have a build process that wraps my modules in a closure and exports the public api to the namespace. This technique is also used by jQuery. You can see that in their source code (look at intro.js &amp; outro.js) on <a href="http://github.com/jquery/jquery/tree/master/src/" rel="nofollow noreferrer">Github</a>.</p> <p>This would allow you to use a pattern that allows your IDE (or ctags with vim) to see your api, whilst also preventing the pollution of the global namespace.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload