é³æ¥½ç¨CoffeeScriptãä½ãã (2) å®è¡ç°å¢ã®æ§æ
2013/10/09 追è¨: ãã®è©±ã¯å¤ãã§ããæ§æãåè¦ç´ãã¾ããã
å®éã«å®è¡ã§ããç°å¢ãä½ã£ããã§ããã¯ã¤ããã¤ãºãè´ãããã§ããªãã
å®è¡ç°å¢ã¯ããããæ§æã«ãªã£ã¦ããã
window
ãã³ã¼ã(é常使ç¨ã®JavaScript)ãå®è¡ããå ´æiframe
ã¯è¨èªã©ã¤ãã©ãªã®å®è£ å ´æãCoffeeColliderã®ã³ã¼ãã¯ããã§å®è¡ãããworker
ã¯ä¿¡å·å¦çãè¡ãå ´æ
ãããã iframe ãçµç±ããã®ã¯ã©ã¤ãã©ãªã§ã°ãã¼ãã«å¤æ°ããããã¿ã¤ãæ¡å¼µãè¡ããããããiframe 㯠sandbox ã§ã»ãã¥ãªãã£çãªå¹æãå¾ããããã¨æã£ããã©ãiframeãã¹ã¯ãªããã¿ã°ãåçã«æ¿å
¥ãããããã(ããããã®)ã 㨠allow-same-origin
ãä»ããªãã¨åããªãã£ã½ããã©ãã«ãæ¹åããããä¿¡å·å¦ç㯠WebWorker ã§ããå¿
è¦ã¯ãªãã¨æããã©ãããããã»ããæ ¼å¥½è¯ãæ°ãããããã¢ãã¼ã¸ã®ãã¯ã¤ããã¤ãºãWebWorkerç£ã®è²´éãªãã¯ã¤ããã¤ãºãªã®ã§ãã£ãã
使ãæ¹ã¯é£ãããªããªãããã«ããã以ä¸ã®ãããªæãã
<script src="coffee-script.js"></script> <script src="coffee-collider.js"></script>
var cc = new CoffeeCollider(); cc.exec("10pi", function(res) { console.log(res); // <-- 31.41592 }); cc.play();
ã¹ã¯ãªããã¯æ©è½ãã¨ã«3種é¡ã«åããã»ããããããã ãã©ä½¿ãæ¹ã®èª¬æã¨ãé¢åã«ãªãã®ã§ã1ã¤ã®ã¹ã¯ãªããã使ãã¾ããã¦ã³ã³ããã¹ãã«ãã£ã¦åä½ãåãæ¿ããããã«ãã(ããããæãã§)ã
ã³ã¼ã㯠amd ã§ããã«ããããããã®ã¯ grunt ã使ã£ã¦ããã次ã¯ãã®ãã¨ãæ¸ãã¾ãã