Reputation: 17381
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>
Upvotes: 3
Views: 226
Reputation: 265151
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 e
will not be visible nor accessible outside the function block
Upvotes: 11