0

I'm trying to document some of my JavaScript according to this JavaScript Documentation guide and came across member access (private, public, protected). I was wondering what the classification would be of a member/function that was defined in the child class but only available in the child class's and it's parent's scope similar to the code snippet below.

Right now the methods initialize and returnItems are declared as public members inside homeBrew.queries.documentLibrary, but they aren't accessible outside of the homeBrew.queries class. Would they then be considered private, since they aren't globally accessible?

var homeBrew = homeBrew || {};

var homeBrew.queries = function () {
    var documentLibrary = function () {
        var siteContext = null;

        var initialize  = function (url, viewName) { /* ... */ }
        var getContext  = function () { /* ... */  }
        var sortItems   = function () { /* ... */  }
        var returnItems = function (callback) { /* ... */ }
        return {
            init: initialize,
            returnItems: returnItems
        }
    }

    var listLibrary = function () {
        // ...
        return { /*...*/ }
    }

    var libraryType = null;
    var queryDocumentLibrary = function (url, viewName) {
        libraryType = 'Document'
        documentLibrary.initialize(url, viewName)
    }
    var queryListLibrary = function (url, viewName) {
        libraryType = 'list'
        listLibrary.initialize(url, viewName)
    }
    var returnItems = function (callback) {
        switch (listType){
            case 'library':
                documentLibrary.returnItems(callback);
                break;
            case 'list':
                listLibrary.returnItems(callback);
                break;
            default:
                console.log('No query executed');
        }
    }

    return {
        queryDocuments: queryDocumentLibrary,
        queryLists: queryListLibrary,
        returnItems: returnItems
    }

}

  • Aren't these closures? – candied_orange Jul 31 at 19:38
  • @candied_orange they might be, but since I have to work with IE a lot, true classes (which were introduced with ES6) don't work. So I found this module/namespace method to emulate classes to a degree. – KGlasier Jul 31 at 20:19
  • Have you considered an ES6 shim? – kevin cline Jul 31 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.