javascript - A function that gets called outside the flow of control? -


so, i've been trying understand specific js library running through browser's debugger, , happens confuses me.

i first encountered in phaser game library, i've seen library well. i'll use phaser example:

<script> (function(){     var game = new phaser.game(800, 600, phaser.canvas, '');     game.state.add('game', game);     game.state.start('game'); })(); </script> 

so anonymous function finishes setting things up, , step on , out of function, , after couple more steps (the pointer sitting @ top of html doc in meantime) program out of ends here:

phaser.device._readycheck = function () {  var readycheck = this._readycheck;  ....  } 

it didn't within flow of control called function, how did here? what's calling function? i've read bit 'asynchronous functions' , sounds pretty explanation, stuff i've glanced @ on google don't explain well, can't understand enough sure. i'm relatively new javascript.

the library sets event handlers various events called asynchronously. in case, event handlers setup to watch completion of loading of dom, among other things, internal state of library can initialized. can see how happens in source

src/system/device.js:phaser.device._readycheck

and phaser.device.whenready in same file. little searching can find calls whenready.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -