1 decade ago
by paulh
Hi
If i have two functions in main init:
player_things();
get_stuff();
How do i prevent get_stuff from being called until player_things has finished .. im guessing this is the elusive CALLBACk thing i've been trying to work out?
1 decade ago
by jswart
To do as callback i'm pretty sure:
function player_things(callback) {
// player_things here
callback(options, needed_for, callback);
}
function get_stuff(options, needed_for, callback) {
// do get_stuff things here
}
It seems like in your case, you could just call get_stuff() at the end of player_things. Not the most functional answer though. Depends on if you use get_stuff() in any other context.
function player_things() {
// player_things code
function() {
// get_stuff code here
}
}
With regard to original post: Unless I'm mistaken though I'm pretty sure get_stuff will not be called until after player_things finishes execution? Or is that incorrect, still new to JavaScript?
1 decade ago
by paulh
Yea i didnt think get_stuff would be called till after player_things but it definitely is in this instance ....
I do call get_stuff at other times, and was hoping to get away form my "chaining spaghetti code", hence my re-write ... i dont need to pass variables back into get_Stuff though .. so maybe callback isnt the right idea after all?
Thanks!
Hmm... that's kind of weird, paulh. I wouldn't expect it to run without finishing player_things()
Unless theres some kind of threading or async type stuff going on the code runs top down.
1 decade ago
by paulh
Yea thats what i thought too .. but player_things is A BIG FILE and somehow get_stuff (which is very small) is done before it (unless its the developer console being behind?)
Ah! Now that you mention the dev console this sounds familiar.
Check this example out in different browsers:
http://jsfiddle.net/j59n5/
In chrome, the dev console shows that both objects contain the key = B
In firefox, firebug shows both A and B.
I'm not certain if this is the problem you're experiencing, but it's worth a shot.
1 decade ago
by paulh
THANK YOU!
Yes , bye bye chrome and hello firefox!
two days down the pan rewriting shit, lol.
Page 1 of 1
« first
« previous
next ›
last »