Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3437946
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:07:39+00:00 2026-05-18T08:07:39+00:00

I’m building a library (https://github.com/OscarGodson/storageLocker), a localStorage wrapper to be more exact, but because

  • 0

I’m building a library (https://github.com/OscarGodson/storageLocker), a localStorage wrapper to be more exact, but because this is my first try at OO JavaScript I’m still learning and I have a couple questions.

  1. I’ve seen in other libraries that sometimes they wrap them in a anonymous function. Do I, or should I, do that with this? And if so, how without breaking anything?

  2. For the internal API (basically, the internal functions) how should I write them? Should add them to the main object e.g. storageLocker.prototype.myInternalFunction() or just myInternalFunction() randomly in my script? I didn’t want the functions to be global though… One of the functions for example just checks a bunch of items in the JSON, sees if their objects, and then checks what the object type is (like Date()) and then converts it.

  3. How/where should I add global, to my script, vars? e.g. i have a var called patterns that is something like var patterns = {"date":/\/Date\(([0-9]+)\)\//} how should I add that into my script?

Thanks a lot. I want to write my script the right way so im asking you guys. I don’t know of any JS guys locally that do any OO JS, they’re all old school types…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:07:39+00:00Added an answer on May 18, 2026 at 8:07 am

    http://nefariousdesigns.co.uk/archive/2010/10/object-oriented-javascript-follow-up-part-2-technical/

    has a decent section on namespacing worth reading.

    http://yuiblog.com/blog/2007/06/12/module-pattern/

    is also another good overview.

    For more great material on good javascript practices, check out

    http://javascript.crockford.com/

    After our discussion in the comments, I’ve changed the example to this:

    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);
    

    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 storageLocker object, it’s returning the ‘public’ object, but that object has access to the storageLocker‘s scope through closure.

    There could be other better ways to do this by perhaps returning the storageLocker object itself, but that would require a bit more thinking through.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.