Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
How to make a class in a another class in JavaScript?

I want to make something like bla.FooBarBaz in JavaScript, but, bla is a class and FooBarBaz is a class, but INSIDE THE bla CLASS. How to do it?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

There are no nested classes in ES6 but yes, you can put a second class as a static property on another class, like this:

class Parent {
    //code
}
Parent.B = class {
   //code
};

or by using extra scope:

var dataClass;
{
    class D {
        constructor() { }
    }
    dataClass = class DataClass {
        constructor() { }
        method() {
            var a = new D();  // works fine
        }
    }
}

But with the help of this proposed class, you can write a single expression or declaration:

class Parent {
    //code
    static Child = class {
         //code
    }
};
about 4 years ago · Juan Pablo Isaza Report

0

You can try sth like this;

class bla {
   constructor() {
     this.FooBarBaz = new FooBarBaz();
   }
}

You can also use static

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!