I guess it is quite regular issue, but for some reason I cannot find the answer on the net.
So I have a class A:
class A {
const data = {...}
}
And a class B in a separate js file.
class B {
// how can I get const data here?
}
I guess it is quite regular issue, but for some reason I cannot find the answer on the net.
So I have a class A:
class A {
const data = {...}
}
And a class B in a separate js file.
class B {
// how can I get const data here?
}
You could use composition, and instantiate new instance of class A inside of constructor of class B.
class A {
constructor() {
this.data = { foo: "bar" };
}
}
class B {
constructor() {
this.instanceOfA = new A();
console.log(this.instanceOfA.data);
}
}
console.log(new B());