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 812755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:15:07+00:00 2026-05-15T01:15:07+00:00

I follow a module pattern where I instantiate components, however, a lot of time

  • 0

I follow a module pattern where I instantiate components, however, a lot of time a component will only be instantiate one time (example: a comment system for an article).

For now I instantiate in the same JS file. but I was wondering if it is the wrong approach? It kind of make no sense to instantiate in the same file and always only once. But at the same time, if this file is in the page I want to have access to my module without instantiate from elsewhere, and IF I need another instance, I just create another from elsewhere…

Here is the pattern I follow:

  ApplicationNamespace.Classname = function() {
      // constructor    
      function privateFunctionInit() {
          // private
      }
      this.privilegedFunction = function() {
          // privileged
          privateFunction();
      };
   privateFunctionInit()
  };
  ApplicationNamespace.Classname.prototype = {
      Method: function(){}
  }
  var class = new ApplicationNamespace.Classname();

What do you think, wrong approach, or is this good?

  • 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-15T01:15:08+00:00Added an answer on May 15, 2026 at 1:15 am

    I don’t think there’s anything inherently wrong with this. We have a lot of JS classes in the codebase at my job that uses this pattern. Even though you’re essentially using the class as a singleton, structuring it this way allows you to create more instances in the future with ease, should you ever need to.

    In my own projects, I tend not to instantiate JS classes from within the file that defines them. I have a separate script that will instantiate whatever classes are needed on a page and work with them accordingly. That approach is probably more modular, but if you’re only ever using one instance, it’s mostly a matter of preference.

    If you’re sure you’re never going to use more than one instance of the class, you could simplify things by creating a singleton object with object literal notation.

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

Sidebar

Related Questions

This question is a follow up on one of my other questions, Can I
I researched the ItemAdd event and created a class module that follows the example.
In follow up to this question , it appears that some numbers cannot be
General Follow the same standards for all tests. Be clear about what each test
To follow on from my question yesterday.... MySQL Table Design for a Questionnaire I
This is a follow on question to How do I delete 1 file from
This is a follow-on question to the How do you use ssh in a
This question is a follow up to my previous question about getting the HTML
This is a follow up question to This Question . I like (and understand)
Update: Check out this follow-up question: Gem Update on Windows - is it broken?

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.