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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:59:43+00:00 2026-06-01T11:59:43+00:00

1.)If I call a static function like below and have to perform an additional

  • 0

1.)If I call a static function like below and have to perform an additional operation on some data passed into the static function. Will calling a nested an inner function create a closure?
What I am after is to keep the operations like MakeSomethingOk unavailable to the global scope, since the MakeSomethingOk is only relevant to the Person.PerformSomeTypeOfOperation

2.) Is there anyway to access a collections object like _persons[] from other static function constructors, as in shared? Without having to do a Persons._persons

3.) Is a function constructor still referred to a a constructor if the function is static?

    function Person() { };
    function Persons() { var _persons = []; };
    Person.PerformSomeTypeOfOperation = function (someThing) {

        if (someThing == 'turnsOutToBeOk') { return 'anyThing' }
        else {
            function MakeSomethingOk() { }

            //someThing is now being made Ok
        };
    };

Update for answer (1.) below.

    function Person() { };
    function Persons() { **protected static** _persons = []; };

    Person.Operation1 = function (person) {

    if(person.id == _persons[0].id){}//do something
    };

    Person.Operation2 = function (person) {

    if(person.height > 7){//do something, like call NBA
           _persons.push(person);
           }
    };

    Person.Operation3 = function (person) {

    if(person.isHungOver){//do something, like call AA
           _persons.slice(3,1);
           }
    };

So I am trying to access the same static field without exposing it to the public, and still be able to work with the list object.

  • 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-01T11:59:44+00:00Added an answer on June 1, 2026 at 11:59 am

    Local functions are perfectly fine (functions defined within another function) and they are used for a couple reasons. First, they do limit the scope that they can be called to within the function they are defined in. Second, they have access to the arguments and local variables of the parent function:

    Person.PerformSomeTypeOfOperation = function (someThing) {
    
        function MakeSomethingOk() { /* code here */ }
    
        if (someThing == 'turnsOutToBeOk') { return 'anyThing' }
        else {
            MakeSomethinngOK();
        };
    };
    

    One would typically define them at the beginning of the parent function because the javascript interpreter will “hoist” them to that location anyway.

    As to your second question, static functions can have static data. So, you could have Persons.list = [] and then anyone could access that data as Persons.list, including other functions. If you want private data that only the member functions can access, then you will have to use a different construct like here.

    Your third question is pretty much just a semantic question. Usually the point of a constructor is to create/initialize an object. If you’re only going to have a singleton (one static object), I think of it more as a one time initialization rather than a constructor that could be used for multiple objects, but that’s really just my opinion – I don’t think there’s an exact definition that distinguishes between create/initializing a singleton vs. multiple objects in this context.

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

Sidebar

Related Questions

I have a function like the below. I ran into a problem were i
Is it possible to call a c(++) static function pointer (not a delegate) like
I have this static callback function in MyClass, and I try to call another
I want to create macros that will insert a parameter into a function call.
I'm hoping to call a static dictionary function using call(). By static I mean
I have a C# library. From within it, I want to call a static
I have a use case where I need to call a (non-static) method in
Under gcc (g++), I have compiled a static .a (call it some_static_lib.a ) library.
I have a static library (let's call it S) that uses a category (NSData+Base64
I am have written the following code below to encode a bitarray into custom

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.