At the most basic level, something of the form (function(){...})()
is a function literal that is executed immediately. What this means is that you have defined a function and you are calling it immediately.
This form is useful for information hiding and encapsulation since anything you define inside that function remains local to that function and inaccessible from the outside world (unless you specifically expose it - usually via a returned object literal).
A variation of this basic form is what you see in jQuery plugins (or in this module pattern in general). Since you are defining a function literal, it doesn't have access to anything from the outside world unless you explicitly pass in the information. Hence:
(function($) {
...
})(jQuery);
Which means you're passing in a reference to the actual jQuery
object, but it's known as $
within the scope of the function literal.
'코드 > JS' 카테고리의 다른 글
ie6에서 png 이미지 디스플레이 (0) | 2013.10.10 |
---|---|
제이쿼리 여러 함수 플러그인 작성 (0) | 2013.08.23 |
jQuery.extend (0) | 2013.06.27 |
자바스크립트로 stylesheet 파일 로드하기 (0) | 2013.01.15 |
자바스크립트 반복문 ;i++<len; (0) | 2013.01.13 |