Answer the question
In order to leave comments, you need to log in
Why is the context lost when passing a class to another class?
In the last console log, the prop disappears somewhere.
class Stack {
lols = [];
addLol(lol) {
this.lols.push(lol);
}
}
const stack = new Stack();
abstract class BaseLol {
constructor(...prop) {
stack.addLol(this);
this.init(...prop);
console.log(stack); //Stack { lols: [ Lol { prop: 'qwe' } ] }
}
abstract init(...prop);
}
class Lol extends BaseLol {
prop;
init(prop) {
console.log(prop); //qwe
this.prop = prop;
}
}
new Lol("qwe");
console.log(stack); //Stack { lols: [ Lol { prop: undefined } ] }
Answer the question
In order to leave comments, you need to log in
В общем проблема была в tsconfig, стоял "target": "ESNext", поменял на ES6 стало норм
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question