I think the question title sums it up pretty well, if not, let me explain:
I have a class, that one has a function and inside that function A I NEED to have another function (function B), which needs to access a variable of function A. I hope this is enough, I really can not find any better words of how to describe this issue.
I think you need arrow functions for that
class Some() {
constructor() {
/* ... */
}
A(params) {
let localVariable = 1
const B = () => {
// here you can access to the context (this)
// and to A local variables (params, localVariable )
}
}
}
If i understood you correctly. And please ask more specific questions next time. Also try to share your code. It would be easier to understand
This sounds like a design problem. It sounds like you're attempting to break variable scoping rules. It seems to me, that this is what you're trying to do:
class some_class {
A_function() {
let variable1 = 5;
}
B_function() {
let variable1 = 10;
}
}
'variable1' is defined in A_function and is not accessible to B_function because of scoping rules. In fact, the variable1 in A_function and the variable1 in B_function are different variables.
However, a better implementation, that would likely work as you intend would be more like this:
class some_class {
constructor() {
this.variable1 = 5;
}
A_function() {
this.variable1 = 10;
}
B_function() {
this.variable1 = 15;
}
}
Now, this.variable1 is defined as a property of the class and is accessible to both functions. Either function can modify the value of the variable.
Is this what you have in mind?