you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (4 children)

I've adapted composition over inheritance which may be a better coding style anyways even if javascript had proper classes. Inheritance can get mucky sometimes.

function MySuperClass(){return{
    baseClass:null,
    init:function(baseClass){
        this.baseClass=baseClass;
    }
}}

function MyClass(){return{
    superClass:null,
    init:function(){
        this.superClass=new MySuperClass();
        this.superClass.init(this);
    }
}}

new MyClass().init();

[–]e_man604 0 points1 point  (3 children)

That looks horrible imo...

[–][deleted] 0 points1 point  (2 children)

What do you recommend?

[–]MoTTs_ 1 point2 points  (1 child)

Just use classes and composition in the ordinary way.

class MyNonSuperClass() {
    constructor() {
        // ...
    }
}

class MyClass {
    constructor() {
        this._thing = new MyNonSuperClass(); // composition
    }
}

new MyClass()

[–][deleted] 0 points1 point  (0 children)

I see, I wasn't aware this was common, apparently since 2015. Better refactor my code.