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

  • Home
  • SEARCH
  • 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 8939099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:45:36+00:00 2026-06-15T10:45:36+00:00

This is a js pattern I’ve found myself using and tweaking over the years.

  • 0

This is a js pattern I’ve found myself using and tweaking over the years.

The thing is, I fell into it after some experimentation and I’m keen to know whether this type of pattern has a name. I’ve browsed through a lot of design patterns but not found anything similar (or as simple, especially for modular type patterns).

var FOO = (function ($) {
    var privateFuncA = function() {
        ...
    },        
    privateFuncB = function() {
        ...
    },
    self = {
        init: function() {
            privateFuncA(); // Call a private func
            self.publicFunc(); // Call a public func
        },
        publicFunc: function() {
            ...
        }
    };
    return self;
}(jQuery));

$(function () {
    // Initialise FOO
    FOO.init();
});

Idea is to keep everything namespaced and allows for pseudo-public/private funcs.

If I need to go modular I’ll extend the base FOO object:

// Extend FOO object
FOO.Bar = (function ($) {
    var privateFunc = function() {
        ...
    },
    self = {
        publicFunc: function() {
            ...
        }
    };
    return self;
}(jQuery));

If you want to call publicFunc in the extended object from outside you can:

FOO.Bar.publicFunc()

Does anyone know if this type of pattern has a name or whether there’s any known issues with such a design?

  • 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-06-15T10:45:37+00:00Added an answer on June 15, 2026 at 10:45 am

    Sure. It’s just an extension of Christian Hielmann’s “Revealing Module” pattern, which was itself an extension of Douglas Crockford’s Module pattern.

    In a lot of my examples here on SO, I’ll use something very similar, except replacing self with public_interface, to try to make it more obvious as to what is public, private or private-static.

    var built_module = (function () {
    
        var private_data = "",
            private_method = function () { /* ... */ },
    
            public_interface = {
                public_method : function () { /* ... */ },
                public_data
            };
    
        return public_interface;
    
    }());
    

    and as a constructor:

    var built_constructor = (function (env_params) {
    
        var static_data = "",
            static_method = function () { /* ... */ },
    
            public_constructor = function (params) {
                var private_data = "",
                    private_method = function (params) { /* ... */ },
    
                    public_interface = {
                        public_method : function () { /* ... */ },
                        public_data
                    };
    
                return public_interface;
            };
    
        return public_constructor;
    }(envArgs));
    
    
    var myInstance = built_constructor(myArgs);
    

    The “static” data/properties are in an outer-closure, so all of the vars/functions within the inner-closure have access to them, while the “static” methods have no access to any instance-methods/data, without passing arguments into the function.

    You can extend it in any way from here — removing the return value, and instead assigning the public_interface as a property of an object, or window by default (for namespacing).

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

Sidebar

Related Questions

Where in this pattern I can place services, about which I some much hear
I am using this pattern and matching a string. String s = //name:value /name:value;
I ran across this pattern in the code of a library I'm using. It
I've been using this pattern to initialize static data in my classes. It looks
This is my first experience with pattern matching using regular expressions so any help
I find myself breaking this pattern all the time. YAGNI - You Ain't Gonna
I have this pattern: Thing * y = FindNearestItem(); if (y && (MenuElement *
I saw use of this pattern to concatenate onto a string in some code
i use this pattern '/(\{(\w+)\}(.*))?\{%(\w+)%\}((.*)\{\/(\w+)\})?/i' to extract tags from a template using preg_match function.
Not sure what this pattern is called, but here is the scenario: class Some

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.