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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:55:58+00:00 2026-06-15T04:55:58+00:00

From a single instance and a multiple instance point of view, why would I

  • 0

From a single instance and a multiple instance point of view, why would I write all those extra lines of code following the Module Pattern vs just using a standard Constructor with methods and properties defined in the constructor body?

Module Pattern sample : http://jsfiddle.net/T3ZJE/1/

var module = (function () {
    // private variables and functions
    var foo = 'bar';

    // constructor
    var module = function () {
    };

    // prototype
    module.prototype = {
        constructor: module,
        something: function () {
        }
    };

    // return module
    return module;
})();

var my_module = new module();

console.log(my_module)

Constructor sample : http://jsfiddle.net/EuvaS/2/

function Module(){

    // private variables and functions
    var foo = 'bar';

    //public methods
    this.something = function () {

    }        
}

var my_module = new Module();

console.log(my_module);

To me the end result is pretty much the same. Both can have public properties and methods, both can have “private” variables and methods which can be accessed by the public methods.

Both will define public / prototype methods once for a singleton, both will define them multiple times for multiple instances / clones of the object.

Am I missing something? What is the difference?

  • 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-15T04:55:59+00:00Added an answer on June 15, 2026 at 4:55 am

    In the first example, foo will be a static variable common to all instances of module(). Meaning, all instances will reference the same variable.

    In the second example, foo is different for each Module() instance.

    Apart from that, I don’t see any difference.

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

Sidebar

Related Questions

I want to open Multiple Instance of a single from , and running simultaneously
I am using following C function to create multiple network namespaces from a single
I'm currently managing multiple models from a single SITE MANAGER page. I have the
I want to create multiple versions of print-friendly pages from a single page. I
I'm wondering if anybody knows how to get multiple counts from a single query
I would like to upload multiple files using a single form field via Python
I have multiple classes that need to share a single instance of another class.
I see WCF provides persession/percall/single instance modes and single/multiple/reentrant concurency model. Currently I am
Crystal Reports in Visual Studio 2008 with C# Normally Data from single column comes
Can I generate different Windows Installer versions (4, 4.5 or 5.0) .MSI from single

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.