i see the following code in a lot of java-script files.
(function () {
//code goes here
})();
Can somebody explain this, or point me to a tutorial that explains this?
i see the following code in a lot of java-script files.
(function () {
//code goes here
})();
Can somebody explain this, or point me to a tutorial that explains this?
This is a code block, an immediately executing function to be exact, which basically prevents variables you define to leak into a global scope (which is a horrible thing and can lead to hard to track bugs)...
There is a good video you can watch on youtube Fundamentals for Great jQuery Development where a much more knowledgeable person goes over this technique in the first part of it. I advise you to watch it :)
EDIT
Fixed the link to point to an intended video