1

I have a javascript function which is called from another function I have.

For some reasons, this function is not executed each time when called. I have tryed to change the name of the function, and then everything works fine.

I don't understand why. Here is a litle example:

javascript 1:

function a()
{ 
   b();
}

javascript 2:

function b()
{ 
   c();
}

javascript 3:

function c()
{ 
   alert("Function c");
}

The function c is not executed for some reasons... If for example the function c will be called newC(), then it works fine.

5
  • 1
    Are these three different compilation blocks (e.g. files)? What are you actually executing; these are just definitions of functions, how do they get called? Commented Aug 2, 2012 at 8:08
  • Could you please provide a running example with proper comments? There is no call to a in your current example. Commented Aug 2, 2012 at 8:12
  • Thank you for your ansewer @AndrzejDoyle. Function a() is in separate js file and function b() and c() are in the same js file. I am actually executing the first javascript file with the function a(), then that function will call the function b from the second js file and the function b() will call the function c() from the same file. Commented Aug 2, 2012 at 8:13
  • @Zeta, thank you for the answer. The function a() is called when a button iz clicked. The function b is executed properly but not the c. Commented Aug 2, 2012 at 8:15
  • you said you changed the function names and it worked fine, so please post the original code you wrote with the non-working name. Probably that name was already used by other function... Commented Aug 2, 2012 at 8:15

2 Answers 2

5

You probably have a conflict of names in the scope of b() i.e. when b() is executed, it can happen that c is defined to something else in a current scope.

Solution: Start your JavaScript debugger, set a breakpoint in b() and check what c is at that time.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, you're right @Aaron, I have run the debuger and I defined another function with the same name in the js file b, so there was a name conflict. Stupid error from my side. Sorry and thanks again.
1

For me it works fine. May be you have some error in the code. IF u post the full code i may able to help. here is the working code

<html>
<head>
<script type="text/javascript">
function a()
{
b();
}
function b()
{
c();
}
function c()
{
alert("hello");
}
</script>
</head>
<body>
<form>
<label>Hello</label>
<button onclick="a()">v</button>
</form>
</body>
</html>

1 Comment

Thanks, I have found the solution, I defined the function c twice, so there were name conflicts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.