Possible Duplicates:
Is the following JavaScript construct called a Closure?
What do parentheses surrounding a JavaScript object/function/class declaration mean?
How does the (function() {})() construct work and why do people use it?
Difference between (function(){})(); and function(){}();
Hi,
As i was viewing a site with just simple html text and no graphics i thought of viewing its code.
When i did so i found this script
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-13137273-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
is there is any special purpose of using code like the following
(function() { /*code;*/ })();
i have seen it in jquery. But still i am not much comfortable with the free style of extreme javascript programming.
Suggestions, comments and answers. Any would be nice.
THX
[i am writing this after the first answer. extreme in the sense ... which i did not find in other programming languages and which is unable for me to guess what that might be. besides there are lots of extraordinary option in javascript which i had mentioned as extreme. maybe i should have used another work.]