Mike
Mike

Reputation: 23

Adding Subclass to Main Class in JavaScript

var Test = {

    Hoi : {
        test: function(e) {
            console.log(e);
        }
    },

    c: function(e) {
         console.log(e);
    }
};

Test.c("hey 1");
Test.Hoi.c("hey 2");

I've doing some classes exercising, but I can't manage to put subclasses into a main class.

Upvotes: 0

Views: 345

Answers (2)

JKirchartz
JKirchartz

Reputation: 18022

Test.Hoi.c doesn't exist; Test.Hoi.test does use:

Test.Hoi.test("hey 2");

each dot basically digs a step deeper into the structure of the object.

Upvotes: 3

Radonirina Maminiaina
Radonirina Maminiaina

Reputation: 7004

You must create the c method.

...
Hoi : {
    test: function(e) {
        console.log(e);
    },
    c: function(e) {
        console.log(e)
    }
}
...
Test.Hoi.c("hey 2");

Upvotes: 0

Related Questions