Let's say that:
a() {
console.log("i am a")
}
b() {
c() {
//call function a here
}
}
How do I call function a
from function c
?
Let's say that:
a() {
console.log("i am a")
}
b() {
c() {
//call function a here
}
}
How do I call function a
from function c
?
functions declared like you are declaring them are hoisted to the top of the scope. a
is available globally and can be called by anything inside the same global scope.
I have solved my problem with using an arrow function on parameter of c.
The way your functions are defined shows that c is nested inside of b which effects the scope when the function executes. First, you would have to figure out a way to call function c. Since it is inside of function b, you will first need to call function b to get to function c. Accessing function c is not possible with your code.
The below code would allow you to call function c, which then calls function a.
function a() {
console.log("i am a")
}
function b() {
this.c = function() {
//call function a here
window.a();
}
return this;
}
b().c()