Skip to content

Instantly share code, notes, and snippets.

@kiyeon
Created March 17, 2018 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiyeon/228e9e8056e846d97791d700f2890306 to your computer and use it in GitHub Desktop.
Save kiyeon/228e9e8056e846d97791d700f2890306 to your computer and use it in GitHub Desktop.
안전한 jQuery 영역 만들기
// '$'를 사용하는 다른 라이브러리와의 충돌을 피하기위해 IIFE를 사용할 수 있다.
// 익명함수라도 "jQueryScope"처럼 명시하는것이 권장된다. 코드를 쉽게 이해할 수 있도록 돕기위한 용도이며 선택은 자유다.
(function jQueryScope($) {
// DOM 로딩 후 스크립트를 실행한다는 의미다. 렌더링중 스크립트가 같이 실행되면 아직 생성되지 않은 element에 접근하여 스크립트가 올바로 실행되지 않는것을 방지하기 위함이다.
$(document).ready(function() {
});
// 위 코드의 단축형이다.
$(function() {
});
})(window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment