Is it possible to change the class of a Javascript variable ?
Let's say I have 2 classes :
class A {
constructor(x) {
this.x = x;
}
}
class B {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
And one variable of type A
let a = new A(20);
How coulid I change the type of a such that
(a instanceof B)
return true and not false ?
EDIT : I would like to know to solve a specific problem. I have a tree structure where each node of the tree is a Javascript object of class A or B (actually I have more class which all inherit from a base class but let's keep it simple). At some point, I would like to transform a node A into a node B. But I only have access to the node itself, not the parent nodes. So I would like to make a method inside the class A which transform the instanciated variable into an object of class B.