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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:21:42+00:00 2026-06-18T07:21:42+00:00

Thinking about how JavaScript uses functions for scoping of variables, I started to think

  • 0

Thinking about how JavaScript uses functions for scoping of variables, I started to think about what would happen in case of the following example:

var OuterClass = function () {

    var InnerClass = function () {
        this.foo = "bar";
    };

    this.getInstanceOfInner = function () {
        return new InnerClass();
    };

};

var instanceOfOuter = new OuterClass();
console.log(instanceOfOuter.getInstanceOfInner());

Fiddle of the above

Testing the above code in different browsers, the outcome varies:

  • Chrome: Logs an instance of the inner-class and seems to be aware of the class declaration.
  • Firefox: Seems to log an “untyped” object, but with the correct properties.
  • IE9: Logs the string-representation of an object [object Object]

I got somewhat confused about this, what is the deal here? Are class declarations subject to scope, the same way other variables are? Or is it up to each vendor to implement it as they please?

  • 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-18T07:21:43+00:00Added an answer on June 18, 2026 at 7:21 am

    There are no classes and instances in JavaScript, just prototypes and constructor functions (read about the differences here). Those follow the same scoping rules as any other objects. So the constructor function InnerClass itself is not available outside of ÒuterClass but the returned “instance” knows its prototype and browsers may or may not log that.

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

Sidebar

Related Questions

Working on an irc client in Adobe AIR in JavaScript, and thinking about logging.
Just thinking about the best way to build an Order form that would (from
I'm thinking about a system in which I allow users to create Javascript-empowered widgets
I'm thinking about using an accordion in a please enable Javascript page, but I
I have never used a lightbox before, but recently started thinking about using a
I'm thinking about writing some code in JavaScript which I can use in my
I am writing custom form validation javascript library and I am thinking about correct
I have a PHP/MySQL site I'm thinking about converting into a HTML5/JavaScript that could
I've been thinking about javascript programming style, and I was wondering whether it makes
I don't know much about writing good javascript so perhaps I am thinking about

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.