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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:06:31+00:00 2026-05-24T12:06:31+00:00

here is my javascript: function namespace(nameSpaceString){ var parts = nameSpaceString.split(.); var parent = window;

  • 0

here is my javascript:

function namespace(nameSpaceString){
    var parts = nameSpaceString.split(".");
    var parent = window;
    var currentParent = '';

    for(var i=0, len=parts.length; i<len;i++){
        currentParent = parts[i];
        parent[currentParent] = parent[currentParent] || {};
        parent = parent[currentParent];
    }

    return parent;
}
abc = namespace('ns.abc');

abc.common = function(){
    var arr = [];

    setArr = function(v){
        if(v){
            arr.push(v);
        }
    }
    getArr = function(){
        return arr;
    }

    registerArr = function(ns){
        if(ns){
            for(var obj in ns){
                if(obj.hasOwnProperty(getName)){
                    setArr(obj.getName());
                }
            }
        }
    }
    return{
      setArr : setArr,
      getArr : getArr,
      registerArr : registerArr
   }
}

abc.form = function() {
var salutation = "Hi";
var name = '';

getSalutation = function(){
    return salutation;
}
getName = function(){
    return name;
}
setSalutation = function(s){
    salutation = s;
}
setName = function(n){
    name = n;
}

return{
    getSalutation:getSalutation,
    setSalutation:setSalutation,
    getName : getName,
    setName : setName
    }
}

persons = namespace('ns.abc.persons');
persons.Dave = new abc.form();

persons.Dave.setName("Dave");

persons.Mitchell = new abc.form();

persons.Mitchell.setName('Mitchell');
persons.Mitchell.setSalutation('Howdy');

alert(persons.Mitchell.getSalutation()+":"+persons.Mitchell.getName());
commonObj = new abc.common();

commonObj.registerArr(persons);
alert("Registration:"+commonObj.getArr())

commonObj.setArr(persons.Dave.getName());
commonObj.setArr(persons.Mitchell.getName());
alert("Setter Methods:"+commonObj.getArr());

Here the Arr in Common when set by setter method works fine. But when I try to achieve the same by calling setter method form another member function -“registerArr” of the same object, it returns nothing.

How can I use setter method from within another member function?

  • 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-24T12:06:32+00:00Added an answer on May 24, 2026 at 12:06 pm

    You need to declare the variables holding the functions using var.

    Since you aren’t declaring them, the variables become globals.

    Therefore, registerArr will always use the functions from the last instance created, since that’s what’s in the global variables.

    Also, you’re misusing the for… in loop.
    obj iterates over the keys of every property in the object.
    To iterate over an array, use a normal for loop.

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

Sidebar

Related Questions

Window.open javascript function is not working in Mozilla, but working in other browsers, here
I need to pass an url from asp.net load_page to flowplayer javascript function here:
I call a javascript function from a textbox by using OnKeyPress=clickSearchButton() Here is my
here is some sample javascript: SomeObjectType = function() { } SomeObjectType.prototype = { field1:
Here is function , <script type=text/javascript> $(document).ready(function() { getRecordspage(1, 5); $(a.page-numbers).click(function() { alert(1); getRecordspage($(this).text(),
$('#selector').click(function() { // here I would like to load a javascript file // let's
It is valid JavaScript to write something like this: function example(x) { Here is
Here is the situation. I have some javascript that looks like this: function onSubmit()
I have this simple function: <script type=text/javascript> //<![CDATA[ jQuery(function($){ function here(b){alert(b);} ; here(6); });
Trying to truncate some code here and running into a problem: <script type=text/javascript> $(function()

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.