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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:54:43+00:00 2026-06-17T08:54:43+00:00

I’m using the Revealing Prototype Pattern and have 2 different prototypes that I’m putting

  • 0

I’m using the Revealing Prototype Pattern and have 2 different prototypes that I’m putting into the same JavaScript file. These links are to articles I found which relate to this.
http://bit.ly/U83hdg, http://bit.ly/VmJ71h.

I was under the impression that these would operate like atomic classes, where functions associated with one would be unaware of functions in the other.

For instance, both of these prototypes have an “init” and a “set” function. The behavior I’m seeing in the browser is that the last version of “init” gets executed, even when the code references the first prototype name.

This is generic stripped-down code from my two prototypes.

var operationA = function (control, settings) {
   this.control = control;
   this.settings = settings;
};

operationA.prototype = function () {
   init = function () {
      // do something
      return this;
   }
   set = function () {
      // do something
      return this;
   };

   return {
      init: init,
      set: set
   };
}

var operationB = function (control, settings) {
   this.control = control;
   this.settings = settings;
};

operationB.prototype = function () {
   init = function () {
      // do something
      return this;
   }
   set = function () {
      // do something
      return this;
   };

   return {
      init: init,
      set: set
   };
}

This is how I’m instantiating the first object.

var objectASettings = {
   property1: 48,
   property2: 37
};
var objectA = new operationA('#mySelector', objectASettings);
objectA.init().set();

When the above runs, the init and set functions from the prototype for operationB are being executed, instead of executing the init and set functions from the prototype for operationA.

I assumed these prototypes basically namespaced their contained functions. Am I required to create unique public function names for operationA and operationB (like initA , setA, initB, setB)?

Is there a way to self-contain and/or namespace these public functions, so I can expose the same operation names of init and set on 2 different prototypes in the same file?

Thanks for your help.

  • 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-17T08:54:44+00:00Added an answer on June 17, 2026 at 8:54 am

    A couple of things to get it working:

    1. Add var before the first member in the prototype function.
    2. Separate each member with a comma (you can certainly put var in front of each member but I like to keep it clean…personal preference though).
    3. The function assigned to the prototype must be self-invoked for the pattern to work properly.

    Here’s an example that should work for you:

    <html>
    <head>
       <script>
            var operationA = function (control, settings) {
               this.control = control;
               this.settings = settings;
            };
    
            operationA.prototype = function () {
               var init = function () {
                  // do something
                  return this;
               },
               set = function () {
                  alert('set A');
                  return this;
               };
    
               return {
                  init: init,
                  set: set
               };
            }();
    
            var operationB = function (control, settings) {
               this.control = control;
               this.settings = settings;
            };
    
            operationB.prototype = function () {
               var init = function () {
                  // do something
                  return this;
               }, 
               set = function () {
                  alert('set B');
                  return this;
               };
    
               return {
                  init: init,
                  set: set
               };
            }();
    
            window.onload = function() {
                var objectASettings = {
                   property1: 48,
                   property2: 37
                };
                var objectBSettings = {
                   property1: 50,
                   property2: 50
                };
                var objectA = new operationA('#mySelector', objectASettings);
                objectA.init().set();
    
                var objectB = new operationB('#foo', objectBSettings)
                objectB.init().set();
            }
       </script>
    </head>
    

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

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.