-1

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?

user1365010
  • 3,185
  • 8
  • 24
  • 43
  • local variables trump global variables, use a better naming convention. :) – epascarello Jun 05 '12 at 12:09
  • 1
    yes, this questions makes no sense. What you're doing is shadowing a variabile – that often comes to bug hard to find. – ZER0 Jun 05 '12 at 12:12

5 Answers5

1

If all of these functions are defined on the global scope you can use this:

window.b();
Sirko
  • 72,589
  • 19
  • 149
  • 183
1

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.

h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
0

You can call it by two methods

b();

a(b);
Miqdad Ali
  • 6,129
  • 7
  • 31
  • 50
0

Presuming that you need to call the real function b from a, you should write:

window.b();
Alexander Pavlov
  • 31,598
  • 5
  • 67
  • 93
0

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.

Logard
  • 1,494
  • 1
  • 13
  • 27