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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:27:56+00:00 2026-06-11T19:27:56+00:00

I think the best way to ask my question is by giving an example.

  • 0

I think the best way to ask my question is by giving an example.

In JavaScript, imagine the following scenario:

function Tab(options) {
    this.options = options;
}

Tab.prototype.doSomething = function () {
    if(...) {
        // Change tab1's options
        //tab1.disabled = true
    } else {
        // Change tab2's options
        //tab2.disabled = true
    }
    // Call a method on of mySlider instance (NOT myOtherSlider instance)
    //mySlider.helloWorld();
}

// Slider class
function Slider(options) {
   ....
}

Slider.prototype.helloWorld = function () {

    ...
    // Access tab1's properties
    // tab1.disabled should be "TRUE" since it was changed previously

    // Access tab2's properties
    ...
}

function Accordion() {
    this.name = 'accordion';
    var tab1          = new Tab({disabled: true}),
        tab2          = new Tab({disabled: false),
        mySlider      = new Slider({color: red}),
        myOtherSlider = new Slider({color: blue});
}

Pretty much I would like all the classes to be aware of the objects that has been instantiated in their own class as well as other classes.

The important part is for the instances to be synchronized. For example, a change to tab1’s properties should be applied/visible to any other objects accessing tab1.


I managed to answer my own question by using an object manager class:

function ObjectManager () {
}

ObjectManager.objects = {};

ObjectManager.register = function (name, object) {
    var t = this;
    t.objects[name] = object;
}

ObjectManager.getObject = function (name) {
    var t = this;
    return t.objects[name];
}

function Tab () {
    this.name = 'tab object';
}

Tab.prototype.init = function (name) {
    var t = this;
    t.name = name;
}

Tab.prototype.changeProperty = function () {
    var tab1 = ObjectManager.getObject('tab1');
    tab1.name = 'changed tab1 name';
}

function Accordion() {
    var tab1 = new Tab();
    tab1.init('tab number 1');

    var tab2 = new Tab();
    tab2.init('tab number 2');

    ObjectManager.register('tab1', tab1);
    ObjectManager.register('tab2', tab2);
    console.log(ObjectManager.objects);
    tab2.changeProperty();
    console.log(ObjectManager.objects);
    console.log(tab1.name);
}

var accordion = new Accordion();​

Though I am not sure how efficient this solution is, but it gets the job done.

  • 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-11T19:27:57+00:00Added an answer on June 11, 2026 at 7:27 pm

    There are many different approaches to this problem. Let me explain two common patterns:

    1. The observer pattern. Each object which needs to be informed about changes in other objects (“observer”), is passed to the “register” method of the objects it needs to be informed about (“observed”). The observed object keeps an internal array of all observers which registered for it. The observed also registers handlers for all relevant input events on the DOM element it represents (onclick, onchange etc). When the observed is changed, it informs all observers by calling a common method in them.

    2. The controller pattern. All objects are managed by a central controller object. The controller keeps arrays of all objects which need to be managed. All input events are handled by the controller. When an input event occurs, it determines which objects need to be changed because of this event and changes them.

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

Sidebar

Related Questions

I think the best way to ask this question is to provide an example.
The best way I can think of to ask this is by example... In
I think the best way to ask this question is: How do I specify
Hey, I think the best way to ask this question is to show what
I think the best way to ask this question is with some code... can
I think the best way to form this question is with an example...so, the
I'm a little stumped on this one. I think the best way to ask
I think the best way to express my question is by showing an example:
This is the best way I can think of phrasing this question, given this
The best way I think to explain this is to tell you what my

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.