O
O
OneTwoThreeFourFive2021-06-07 15:45:19
JavaScript
OneTwoThreeFourFive, 2021-06-07 15:45:19

Correct reference to an object in js?

Hello. There are 2 objects and each of them must be able to access the other (methods and values) from itself.

class Object1 {
    constructor() {
        this.object2 = new Object2(this);
    }
}

class Object2 {
    constructor(object) {
        this.object1 = object;
    }
}

var object = new Object1();


Is it done right? Or is there another way without inheritance?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-06-07
@vabka

Yes, good.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question