I was reading facebook javascript SDK when I saw the following syntaxt that I don’t understand:
(function(){…}());
Does anyone know what does it do?
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: 'your app id', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
it’s an anonymous function, that gets called immediately after its declaration. It’s used to create local variables without clobbering up the global scope. the variable
ewill not be visible nor accessible outside the function block