How is this function performed independently?

I have the following code (which is the initialization of the facebook API), I don’t understand why this snippet is triggered when loading without calling elsewhere in the code!

The funny thing is that when I fbAsyncInit function "wrapper", it works the same! so how is FB.init called without calling fbAsyncInit anywhere else?

 window.fbAsyncInit = function() { FB.init({appId: '00000000000000000', status: true, cookie: true, xfbml: true}); FB.getLoginStatus(function(response) { if (response.session) { console.log('User is logged in.'); FB.api("/me?fields=name,picture", handleMe); } else { console.log('User is not logged in.'); window.location = "http://wall-et.com/index.php/test/login/"; } }); }; 
+4
source share
1 answer

To do this, you need to include a script from Facebook (possibly connect.facebook.net/en_US/all.js ) on your page.

The script starts window.fbAsyncInit from window.setTimeout(..., 0) , forcing your code to run after the Facebook script is fully loaded and initialized.

+3
source

All Articles