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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:54:15+00:00 2026-05-27T19:54:15+00:00

Can I write nested classes in Javascript? function A() { this.a; this.B = function()

  • 0

Can I write nested classes in Javascript?

function A()
{
    this.a;
    this.B = function()
    {
      this.ab ;
      this.C  = function()
      {
         this.ab = 0;
      }
    }
}

If the above code is correct,then

1.How do I declare an object of type B
2.Whose property is  ab.A() 's  or B() 's?.
3.Inside B() where does the 'this' points to.To A() Or to B()?
  • 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-27T19:54:15+00:00Added an answer on May 27, 2026 at 7:54 pm

    Abstract:

    Calling to function without using new operator means that this will be refer to object in which that function was created.
    For global variables this object is window object.
    Calling using new – function behave as constructor like in classes and this refers to this instance which will been created

    1.How do I declare an object of type B

    First way( as a curiosity ) – by calling to A without using new operator this will be refer to windowobject and B method and all other what was declared with this leaks to global scope because A == window.A => true

    A(); 
    var b = new B; // means => new window.B  //parentheses can be ommited if you invoking without arguments  
    alert( ab )  // alerts 'inside A'  -> value from code presented below
    

    or from instance of A:

    new new A().B  // means => new ( new A ).B  
    

    Be careful.

    2.Whose property is ab.A() ‘s or B() ‘s?.

    As above, it depends of how we’ll accessing to it:

     function A()
        {
            this.ab = "inside A";
            this.B = function()
            {
              this.ab = "inside B";
              this.c  = function()
              {  
                 this.ab = "inside C";
              }
            }
        };
    

    Check this out

    var a = new A;
    a.ab // "inside A"
    a.B(); // in B now 'this' refers to 'a', 'a.ab' will be replaced to 'ab' from inside 'B'
    a.ab // "inside B"
    

    but

    var a = new A;
    a.ab // "inside A"
    var b = new a.B;
    a.ab // "inside A"
    b.ab // "inside B"
    
    // and now
    b.c() 
    b.ab // "inside C" and so on:)  
    

    3.Inside B() where does the ‘this’ points to.To A() Or to B()?

    As above:)

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

Sidebar

Related Questions

So I know I can write my own HTML-encoding function like this: function getHTMLEncode(t)
In SQL Server, you can write nested SQL like this: SELECT T.con FROM (SELECT
I'm learning postgresql and I can't figure out how to write this nested query
Possible Duplicates: Can you write object oriented code in C? Object Oriented pattern in
Can anyone tell me how to write a nested SQL query like SELECT *
I'm wondering what is the fastest way that I can write some code. I
I would like to know the correct way to create a nested object in
Can someone explain weird construction of structural type nested in generics: implicit def Function1Functor[R]:
how can we parcel nested object in an intent? . For example lets say
Can someone help me clean up this nested regex (re.sub) in python, please? I

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.