Answer the question
In order to leave comments, you need to log in
How to access variables of one class from another class?
I suspect (strongly) that I don't understand classes very well.
Suppose there is such a program.
https://codepen.io/Azamat_TURBO/pen/jObqMrx?editor... The
question is: how can I reach importantVar from the SecondClass class, which is in the FirstClass?
Answer the question
In order to leave comments, you need to log in
that I don't understand the classes very well
class FirstClass {
constructor() {
this.importantVar = '1234asd'
}
someFunction() {
alert(this.importantVar);
}
}
class SecondClass extends FirstClass {
constructor(importantVar) {
super();
this.justAnotherVar = 'ooooo';
}
iWannaImportantVar() {
alert(this.importantVar);
}
}
function gasgasgas() {
const firstClass = new FirstClass();
const secondClass = new SecondClass();
firstClass.someFunction();
secondClass.iWannaImportantVar();
}
gasgasgas();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question