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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:37:11+00:00 2026-05-23T18:37:11+00:00

I have a problem in creating instances/objects from a javascript class that I have

  • 0

I have a problem in creating instances/objects from a javascript class that I have written. Can you please check the code and see the output which is at the bottom of the code.

Thanks in advance…
Regards.

//MARKER MANAGER CLASS
            var MarkerManager = (function(){

                var arr = [];
                var arrName = [];
                var counter = 0;

                var MarkerManager = function (args){

                    arr = [];
                    arrName = [];
                    counter = 0;            

                    return {
                        addMarker: addMarker,
                        getMarker: getMarker,
                        getIndex: getIndex
                    }

                };

                function getIndex(){
                    return counter;
                }

                function addMarker(marker){
                    arrName[counter] = marker.name;
                    arr[counter] = marker;
                    counter++;
                }

                function getMarkerNameList(){
                    return arrName;
                }

                function getMarker(li_name){
                    var markerIndex = arrName.indexOf(li_name);         
                    return  arr[markerIndex];
                }



                /*var instance;

                var _static = {

                    name: 'manager',

                    getInstance: function (args){

                        if(instance === undefined){
                            instance = new MarkerManager(args)
                        }

                        return instance;

                    }               

                };

                return _static;
                */

                return function (args){

                    var manager = new MarkerManager(args);
                    return manager;

                }

            })();


            var marker1 = new Marker({name:'test0', lat:3 ,  lng:5, isDraggable:true, iconType:'red' });
            var marker2 = new Marker({name:'test1', lat:33 , lng:55, isDraggable:true, iconType:'red' });
            var marker3 = new Marker({name:'test2', lat:44 , lng:99, isDraggable:true, iconType:'red' });
            var marker4 = new Marker({name:'test3', lat:55 , lng:77, isDraggable:true, iconType:'red' });
            var marker5 = new Marker({name:'test4', lat:88 , lng:65, isDraggable:true, iconType:'red' });

            var manager  = new MarkerManager({test:'test2'}); //MarkerManager.getInstance({map:'testtt'});//
            var manager2 = new MarkerManager({test:'test1'});

            manager.addMarker(marker1);
            manager.addMarker(marker2);
            manager.addMarker(marker3);

            manager2.addMarker(marker4);
            manager2.addMarker(marker5);

            alert(manager.getMarkerNameList());     
            alert(manager2.getMarkerNameList());

        //output is "test0,test1,test2,test3,test4" for both manager objects. How can I separate them 
  • 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-23T18:37:12+00:00Added an answer on May 23, 2026 at 6:37 pm

    You need to move all the variables & functions needed by the manager to the constructor function. Or the MarkerManagers will share the same variables & functions together.

            var MarkerManager = (function(){
                return function (args){
    
                    var arr = [];
                    var arrName = [];
                    var counter = 0;
    
                    var MarkerManager = function (args){
    
                        arr = [];
                        arrName = [];
                        counter = 0;            
    
                        return {
                            addMarker: addMarker,
                            getMarker: getMarker,
                            getIndex: getIndex
                        }
    
                    };
    
                    function getIndex(){
                        return counter;
                    }
    
                    function addMarker(marker){
                        arrName[counter] = marker.name;
                        arr[counter] = marker;
                        counter++;
                    }
    
                    function getMarkerNameList(){
                        return arrName;
                    }
    
                    function getMarker(li_name){
                        var markerIndex = arrName.indexOf(li_name);         
                        return  arr[markerIndex];
                    }
    
    
                    var manager = new MarkerManager(args);
                    return manager;
    
                }
    
            })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem in some JavaScript that I am writing where the Switch statement
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have this inside the HTML that is creating an object in JavaScript var
I have an IFilter written in Delphi that I'm trying to get working under
Hey all, have a slight problem here. In CakePHP I have a controller that
I have a problem creating my own librairie to send email. This is my
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via

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.