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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:44:41+00:00 2026-05-13T20:44:41+00:00

A local function in the closure declares a variable with the same name which

  • 0

A local function in the closure declares a variable with the same name which exists in the closure. So, how could we access closure’s variable from the local function?

function closure()
{
    var xVar; 
    function func1()
    {
        var xVar;
        // how to distinguish local and closure scopes.
        return xVar;
    }
    return function () { return func1(); };
}

Creating a private object and making private variables as properties of this object could help. But I am wondering if there is a better and neat solution. Can a scope chain help?

I have edited to make it a complete closure. Anyway, closures are not much concern here, it could be considered for inner functions however, there may be a solution with closures somehow.

Thanks

  • 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-13T20:44:41+00:00Added an answer on May 13, 2026 at 8:44 pm

    You can’t access the scope chain explicitly in JS. Your problem is the age-old one of variable shadowing, but it’s that much more maddening because in JS, the scope chain is actually there at runtime, it’s just not available for you to access.

    You can play some tricks with rejiggering current scope if you use the hated with operator, but that (as well as arguments‘s caller/callee stuff) really just give you access to objects and functions with their properties. There’s no way to say “give me what xVar means in the n-1 runtime scope from right here”.

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

Sidebar

Related Questions

Is there a way to access the local variable of a function from a
What is the standard way to name a temp variable in the local function?
Possible Duplicate: Is it possible to access outer local variable in PHP? PHP closure
I have a buffered grid on which I've implemented a local sort function (client
s it possible to remove cancel button or override cancel button function from local
I have the following code, in which Boost.Local uses a function callback to load
Is it possible to access outer local varialbe in a PHP sub-function? In below
I have a preg_replace_callback which takes a closure (anonymous) function as 2nd parameter and
I took this from Google Code Playground http://code.google.com/apis/ajax/playground/ /*CLOSURE * When a function is
What is convention for local vars that has same meaning as function argument? If

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.