๐Ÿ”ฐnested type

JS โŸฉ value โŸฉ type โŸฉ nested type

replit โŸฉ nested type in JS

// A
class A {

    // โญ๏ธ nested type: A.B
    static B = class {
        
        // ๐ŸŸฆ static method
        static sayHi() { console.log('Hi') }
        
        // ๐Ÿ”น instance method
        instanceSayHi() { console.log('Hi, I am an instance of A.B !') }
    };
    
}

// test code
A.B.sayHi();                  // Hi
(new A.B).instanceSayHi();    // Hi, I am an instance of A.B !

Last updated

Was this helpful?