-1

I have a simple function that calls other functions:

function update() {
    updateMissiles();
    updatePlayer;
    updateTurbines();

}

They are similar to each other in every way except updatePlayer will not run if I put brackets on the end of it. This doesn't break any code but I'm still curious why it does that?

3
  • 2
    Without knowing anything about updatePlayer, it's impossible to say much. But a function won't run unless it's called, and calling a function means (). Commented Feb 7, 2012 at 16:31
  • @BogdanProtsenko: What is updatePlayer? What do you meand by "updatePlayer will not run" and how you check if it has been run? Commented Feb 7, 2012 at 16:32
  • 1
    What is your specific error message? My guess is that updatePlayer is not a function by the time update executes. Just before updatePlayer, write console.log(updatePlayer) to see what the value is. Commented Feb 7, 2012 at 16:32

4 Answers 4

2

I'm guessing there's an Exception in the updatePlayer method and since you're not calling it in the code you pasted above, you're not getting the Exception.

I would open up the Developer Tools for whatever browser you're using and see if there are any JavaScript Exceptions being thrown.

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

Comments

0

Without knowing more it's impossible to pinpoint exactly, but as a best guess - in the scope of the update function, the updatePlayer variable is not a function.

Try logging or debugging your javascript to find out what is going on.

Comments

0

A function will run only if you put () after it's name. If you don't put brackets you'll get the function's content. For example if you have:

function updatePlayer(){ alert('This is a player');}

And call it without brackets:

alert(updatePlayer);

the alerted output will be

function updatePlayer(){ alert('This is a player');}

This is used if you want to use callback functions.

Comments

0

You are confused. updatePlayer; doesn't invoke the updatePlayer function. updatePlayer(); does. Something else is going on in your code.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.