dedyandy Posted June 18, 2006 Share Posted June 18, 2006 From a call of setTimeout("moveText(" + x + "," + y + ")", 1), could anybody help why the first parameter of setTimeout method takes the form of " + x + "," + y + "? Why not setTimeout(“moveText(x,y)”, 1)?Please note that x and y are used as numbers in moveText function.Thanks,Andy Link to comment Share on other sites More sharing options...
biofreakz Posted June 18, 2006 Share Posted June 18, 2006 From a call of setTimeout("moveText(" + x + "," + y + ")", 1), could anybody help why the first parameter of setTimeout method takes the form of " + x + "," + y + "? Why not setTimeout(“moveText(x,y)”, 1)?Please note that x and y are used as numbers in moveText function.Thanks,Andy<{POST_SNAPBACK}> The reason for why you have to take the form " + x + "," + y + " is simple. The setTimeout function stores the first parameter as a string, the x and y are variables. So when the function moveText function is called, it is called anonymously, so the variables x and y are not going to be available to it. So you have to give it values for the parameters instead of variable references.Hope this helps! Link to comment Share on other sites More sharing options...
scott100 Posted June 18, 2006 Share Posted June 18, 2006 Yes is because the function is stored as a string, this is to stop it from executing immediately rather than at the setTimeOut, so the string must be ended to insert a variable and so forth. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now