What does this statement mean in Javascript?
What is this line doing?:
collider = SYS_collisionManager.newCollider(PLAYER, ALIEN_BOMB, 30, 12, that.hit) ; that.hit has been previously defined like this: that.hit = function() { //whatever I would like to specifically know what's going on with the "that.hit" argument above. Thanks. |
I don't know what library you're using, but it looks like it's being used as a callback: when PLAYER and ALIEN_BOMB collide (which uses the numbers 30 and 12 - perhaps defining the bound box around 'PLAYER'? You'd have to look up the docs for the function) run the function that.hit().
|
It's not a library, it's a paper book I'm reading.
Yes, I think you're right, but could you explain to me how "that.hit" WOULD be set up as a callback? |
When a collision occurs, that routine would be invoked with some set of parameters so that you could remove the poor player, add an explosion, deduct lives or points. (Or maybe it's the other way around ... remove the poor alien bomb, add an explosion, add points. After all, it's your game.)
|
Quote:
Quote:
Code:
function doSomething(callback){ EDIT: I stopped being lazy and checked that my code works, which it does. Any problems are therefore of your own devising :P Hope this helps, |
Sorry for the late reply, thanks a lot for your reply Snark, but I didn't get both lines of your code:
For "doSomething(alert);" , it means you're calling doSomething with an arg of alert, right? ie. it expects that there's a variable called alert, whose value will be passed to doSomething? NOT the Javascript built-in FUNCTION alert, which will popup a window. So how does it work then? And for "doSomething(function(s){ window.location.href = s; });" - well I just don't get it. You're including the function's code as an arg to doSomething? How does that work? By the way, could you recommend a good book on all this stuff? Is "Javascript: A Definitive Guide" a good one? |
Quote:
Quote:
Code:
// Instead of writing |
No idea RE the books, sorry. I've just picked up javascript as I go along, really (I don't do all that much of it anyway).
The long and short of it, as ntubski said, is that functions are values just as 2 and "red" and True are - so they can be passed as variables. |
All times are GMT -5. The time now is 03:32 PM. |