Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p><a href="http://nefariousdesigns.co.uk/archive/2010/10/object-oriented-javascript-follow-up-part-2-technical/" rel="nofollow">http://nefariousdesigns.co.uk/archive/2010/10/object-oriented-javascript-follow-up-part-2-technical/</a></p> </blockquote> <p>has a decent section on namespacing worth reading. </p> <blockquote> <p><a href="http://yuiblog.com/blog/2007/06/12/module-pattern/" rel="nofollow">http://yuiblog.com/blog/2007/06/12/module-pattern/</a></p> </blockquote> <p>is also another good overview. </p> <p>For more great material on good javascript practices, check out </p> <blockquote> <p><a href="http://javascript.crockford.com/" rel="nofollow">http://javascript.crockford.com/</a> </p> </blockquote> <p>After our discussion in the comments, I've changed the example to this:</p> <pre><code>var storageLocker = function (selector) { var _selector = selector || "default value"; function myPrivateFunction() { } var public = { get: function () { return _selector; }, uppercase : function () { _selector = _selector.toUpperCase() return this; } } return public; }; // use: var test = storageLocker("search for this").uppercase().get();; alert(test); </code></pre> <p>While this isn't exactly an example of a library/module (because you're accessing the code by calling the constructor directly), it is an example of keeping the same object in scope for further chaining of methods. Actually it's not returning the <code>storageLocker</code> object, it's returning the 'public' object, but that object has access to the <code>storageLocker</code>'s scope through closure. </p> <p>There could be other better ways to do this by perhaps returning the <code>storageLocker</code> object itself, but that would require a bit more thinking through.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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