Here is my exemple :
function a(b)
{
b();
}
function b()
{
alert("d");
}
function c()
{
alert("e");
}
a(c);//Output e
With the fiddle : http://jsfiddle.net/YqeS3/
How can I fire the real b function from a?
Here is my exemple :
function a(b)
{
b();
}
function b()
{
alert("d");
}
function c()
{
alert("e");
}
a(c);//Output e
With the fiddle : http://jsfiddle.net/YqeS3/
How can I fire the real b function from a?
If all of these functions are defined on the global scope you can use this:
window.b();
If your B function isn't global, and you don't want to use naming conventions, you could create an additional function
function d() {
b();
}
and call that one instead. I still think that you should simply name your argument and your function something else though, as it'd also create much less confusion for any other person (this include the future version of yourself) looking at your code.
Presuming that you need to call the real function b
from a
, you should write:
window.b();
The variable b in your function a is just a local variable which you can name whatever you like. Calling it b within the scope of a will make you unable to call external variables or functions with that name within the functions scope. As answered before here by Sirko, you can call outside the functions scope by the use of the
window.b();
Consider renaming your scoped variables if you have problems.