jQuery.when()ã«deferredsãé åã§æ¸¡ããã
ã¯ããã«
ãjQuery.when()ã«æ±ºã¾ã£ãæ°ã®deferredã渡ãã®ã¯èª¿ã¹ããç°¡åã«åãã£ãã®ã§ãããä¸å®æ°ã®deferredã渡ãæ¹æ³ã調ã¹ãããæå¤ã¨æ¥æ¬èªã§ã¯è¦ã¤ãããªãã£ãããã¡ã¢ã
ç°å¢
- jQuery 1.10.2
æ¹æ³
ã以ä¸ã«æ¹æ³ãè¼ã£ã¦ãã¾ãã
æ¸ãã¦ã¿ãã¨ä»¥ä¸ã®ãããªæãã
$(document).on("ready", function(){ var funcA = function() { var dfd = $.Deferred(); setTimeout(function(){ console.log('a'); dfd.resolve(1,'a'); }, 1); return dfd.promise(); }; var funcB = function(){ var dfd = $.Deferred(); setTimeout(function(){ console.log('b'); dfd.resolve(2,'b'); }, 1); return dfd.promise(); }; var funcArray = []; funcArray[0] = funcA(); funcArray[1] = funcB(); //以ä¸ã®ããã«æ¸ãã¨æå¾ éãã«åä½ããªã(deferredã®é åã«ãªããªãã®ã§ãå½ç¶ã¨è¨ãã°å½ç¶ã§ãã)ã //funcArray[0] = funcA; //funcArray[1] = funcB; $.when.apply(null, funcArray).then( function(){ console.log("when :" + arguments[0][0] + " " + arguments[0][1]); console.log("when :" + arguments[1][1] + " " + arguments[1][1]); } ); } );
ããããjQuery.Deferredèªä½ã«ã¤ãã¦
æåã¯jQuery.Deferredèªä½ã«ã¤ãã¦ãã¾ãããããããªãã¦ã以ä¸ãåç §ãã¦åå¼·ãã¾ããã
- 爆速でわかるjQuery.Deferred超入門 - Yahoo! JAPAN Tech Blog
- jQueryのDeferredを用いたモダンなAjax処理の書き方 - Hack Your Design!
- jQuery.when() | 私的なjQuery他
ãããã«
ãjQuery.when()ã«é
åã§deferredã渡ããå ´åãã©ããã£ã¦å®è¡çµæãåãåãã®ãåãããªãã¦è¦ããã ã®ã§ãããargumentsã使ã以å¤ã®æ¹æ³ãåããã¾ããã§ããã
ããªããã¤ãã¤ããªæ°ãããã®ã§ããâ¦ã