(function($) {})(jQuery);ã£ã¦ä½ï¼ã£ã¦æã£ããããããã試ãã¦ã¿ãè¨é²
ã©ãã§ããã話ãªã®ã§ãããinputã¿ã°ã®autocompleteå±æ§ã«ã¤ãã¦å æ¥ã¯ããã¦ã¡ããã¨ç¥ã£ãæ°ããã¾ããï¼ä»æ´
ããã¨æ¥è¨è¦è¿ãã¨ãæã®æ¹ãéè¨çã ãªãã¨æã£ããã
ãã¼ããããèããã¨ãã¼ã«ã«ã®ãã£ãããªãã¡ã¢ã¯å¤ããã ã
ä»åº¦æ¸ãåºããããããªããã
ã§æ¬é¡ã§ãããå
æ¥jQueryã使ã£ã¦ãããã©ã°ã¤ã³ã®ã³ã¼ããè¦ã¦ã¦ã(function($) {})(jQuery);ãã£ã¦ã©ãããæå³ï¼ã¦æã£ãã®ã§ã調ã¹ããã¨ããã¦ã¾ããã
è¬ã£ã¦æã£ãã®ã¯ããã¾ãã«ï¼ã¤ã
- ä½æ å ¨ä½ãæ¬å¼§ã§å²ãå¿ è¦ãããã®ãã
- function($)ã®ã$ãã£ã¦ä½ï¼
- ï¼åç®ã®æ¬å¼§ã®ä¸ã®ãjQueryãã£ã¦ä½ï¼
ãããã»ã¼ã(function($) {})(jQuery);ãã®å
¨ã¦ãè¬ã£ã¦ãã£ã¦ããããªãã®ã§ããw
http://q.hatena.ne.jp/1226297257
ä¸è¨ã®URLå
ãåèã«ãªãã¨ãªãç解ãã¦ã¿ãã®ã§ã¾ã¨ãã¦ã¿ãã
ãããã¡ããã¨ãã解決ã¯ãã¦ããªãã¨æãw
ã¾ãä¸å¿è¨é²ã¨ãããã¨ã§ãã
ä½æ å ¨ä½ãæ¬å¼§ã§å²ãå¿ è¦ãããã®ãã
ç¡åé¢æ°ã«ãã¦ã³ã¼ããå¤é¨ã¨åé¢ãã¦ä½¿ãããã
大ã¾ãã«ããã¨ãããªæããªã®ã ãããï¼
確ãã«å
¨é¨functionã®ä¸ã«ãªããããé¢æ°åããããã¶ãå¿é
ãèæ
®ããªãã¦ããã®ããï¼ã¨æãã¾ããã
ã§ãä¸ã§å®çµããã¦ãã®ã«å¤ã§ã使ããã£ã¦ãªãã ãããããã
function($)ã®ã$ãã£ã¦ä½ï¼
ä¸è¨URLä¸ã«ãããä¸è¨ã®ã³ã¼ããå®è¡ãã¦ã¿ãããããã¾ããã
(function (x){ alert(x); })("hoge");
"hoge"ãæ¥ã¾ããã
ã©ãããï¼åç®ã®æ¬å¼§ã®ä¸èº«ãå¼æ°ã¨ãã¦æ¸¡ããã¦ãããã®ããã
ã£ã¦ãã¨ã¯ã$ãã¯ãjQueryãã£ã¦ãã¨ãããªãã»ã©ã
ï¼åç®ã®æ¬å¼§ã®ä¸ã®ãjQueryãã£ã¦ä½ï¼
ï¼åç®ã®æ¬å¼§ã®ä¸èº«èªä½ã¯ããã®é¢æ°ã¸ã®"handle"ãããã§ãã
ããããããã¨ã«ãã£ã¦ç¡åé¢æ°ã使ããããã«ãªãï¼ã©ããããã¨ã ããï¼
ã¨ããããï¼åç®ã®æ¬å¼§ãã©ãããæåãããã®ãã確èªãã¦ã¿ãã
(function (a){a})(console.log("aa")); (function (a){console.log(a)})("aaa"); (function (a){console.log("hoge")})(console.log("aaaa"));
çµæ
aa aaa aaaa hoge
1åç®ããªããããããæãããï¼åãaaãã¦è¡¨ç¤ºããã¦ãããã¨æã£ããã ãã©ãªãã
ï¼åç®ã¯ã©ã£ã¡ãåããã¦ãã®ã«ã»ã»ãã¾ãããããï¼ä½
ã¨ããããã¾ãå¼æ°ã¿ãããªãã®ã ãªã¨æã£ã¨ããã¨ã«ããã
ããããããªãã¨ããjQueryãã¯ã©ããããã¦ãã®ã ããã»ã»ã
http://hisasann.com/housetect/2008/06/jquery_1.html
ã¨ãä¸è¨ã®ãµã¤ããçºè¦ãjQueryã«ã¢ã¯ã»ã¹ããæ¹æ³ãæ¸ãã¦ããã
var jQuery = window.jQuery = window.$ = function (ele) {
ã©ãããããã§å¤ã§ã使ããããã«ãªã£ã¦ããããï¼
(function(hoge) {console.log(hoge('#test'))})($);
ã»ããã
windowãªãã¸ã§ã¯ãã«çªã£è¾¼ãã°ã¤ãããã®ãã»ã»ãvar jQueryã«ããããã¤ã£ããçç±ã¯ãªãã ãããã»ã»ã¨æã£ããããã¯ä»ã¯é¢ä¿ãªãã®ã§ã¹ã«ã¼ã
(function() {window.hoge = "aaaa"})(); (function(huga) {console.log(huga)})(hoge);
çµæ
aaaa
ããã使ãããã
var ãªãã®å¤æ°ã«å
¥ããã®ã¨ã©ãéããã ããï¼ãªãã¦ã¡ãã£ã¨æã£ã¦ã¿ããããï¼ä½
èªåãªããªã¾ã¨ã
- ä½æ å ¨ä½ãæ¬å¼§ã§å²ãå¿ è¦ãããã®ãã
ãâç¡åé¢æ°ã«ãã¦ä¸ã®ã³ã¼ããå¤é¨ã¨åé¢ãã¦ä½¿ãããã
- function($)ã®ã$ãã£ã¦ä½ï¼
ãâï¼åç®ã®æ¬å¼§ã®ä¸èº«ï¼ã¤ã¾ãjQueryï¼
- ï¼åç®ã®æ¬å¼§ã®ä¸ã®ãjQueryãã£ã¦ä½ï¼
ãâwindowãªãã¸ã§ã¯ãã«ã¤ã£ãã¾ãã¦ãjQueryã£ã¦ãããªãã¸ã§ã¯ã(?)
ã¨ã¾ãããããªæãï¼ã§ããï¼
ãªãã¨ãªãã¢ã¤ã¢ã¤ãæ´ããããããããã試ãã¦æ¥½ããã£ãã§ãï¼