In below example, I need to access this.methodWhichRequredAnywhere()
inside functionWhichRequiredInConstructorOnly()
.
class Example(){
construtor(){
function functionWhichRequiredInConstructorOnly(){
// warning: invalid code
return this.methodWhichRequredAnywhere + ' complete';
}
this.message = functionWhichRequiredInConstructorOnly();
}
methodWhichRequredAnywhere(){
return 'test';
}
}
Too much explanation about closures in answers to another questions, but I still did not found simple solution to solve above problem.
Note
I understand that above code architecture is contradicting to OOP. Why I used it?
- I suppose,
functionWhichRequiredInConstructorOnly()
will be utilized after constructor will be executed. WillmethodWhichRequredAnywhere
be? - I need to group come declarations in my real class. So
functionWhichRequiredInConstructorOnly()
goes directly below some declarations where it used.