I want to keep a property from the a
instance and modify it in a b
instance.
Consider the following code
class A {
constructor() {
this.a = 1
this.b = 2
}
}
class B {
constructor({ a }) { // I want to pass only the a property, not the whole a instance
this.a = a
}
addToA() {
this.a += 1
}
}
const a = new A()
const b = new B({ a: a.a })
b.AddToA()
console.log(a.a) // here I'd like to have a.a modified here and be 2, but it is 1.
Thanks in advanced.