Answer the question
In order to leave comments, you need to log in
How to reach the class fields while in the method function?
class Foo {
constructor(){
this.defaults = '123'
}
init() {
function bar(){
console.log(this.defaults); // тут не видно
}
}
}
Answer the question
In order to leave comments, you need to log in
No way. But if it is enough for you that the bar() function is not called on the forehead, you need to call it private. Well, either pass the object explicitly in the parameters, and ensure the visibility of the required fields outside the class.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question