A new way to define the properties and functions of a Javascript object?

Possible duplicate:
What is the purpose of wrapping all Javascript files in anonymous functions like "(function () {...}) ()"?

I have come across this unusual coding method many times, and it seems to be becoming popular.

(function (variable) {
    // properties or methods go here

    // some more stuff
})(variable)

It’s hard for me to even research this, because I don’t even know what it's called. I worked with him with jquery with, but I still don't know how this works.

Example:

(function ($) {
    ...
        // code to manipulate the dom
    function init() {
        .....
        }

    $(document).ready(function () {
        init();
    });
})(jQuery);

I only used it because I was updating the code made by another developer.

Is there any advantage in coding? Is there a place where I can learn more about this? If someone understands my question, it will be nice to see some articles that talk about it, or maybe you have an idea on how to make your own.

+3
1

. , ,

?

+1

All Articles