JavaScriptã«ä¼¼ããããªã¹ã¿ã³ã¹ã®è¨èªã«CoffeeScriptã¨ãããã®ãããï¼D3.jsã使ã£ãããã°ã©ã ãæ¸ãã¨ãã«ãµã³ãã«ã³ã¼ãã¨ãã¦ä½¿ç¨ããã¦ãããããï¼
npmã®coffee
ã使ãã¨.coffee
ãªãã¡ã¤ã«ã.js
ã«ã³ã³ãã¤ã«ãããã¨ãã§ããï¼coffeeã³ãã³ãã¯npm
ããã¤ã³ã¹ãã¼ã«ããï¼
$ npm install -g coffee
JSã«ã³ã³ãã¤ã«ããã¨ãã¯
$ coffee -c app.coffee
ãå®è¡ããã ãã§è¯ãï¼ãããå®è¡ããã¨ï¼åãé層ã«app.jsãçæãããï¼
ä¾ãã°app.coffeeå ã§CoffeeScriptã§
myFunction = (arg) -> console.log(arg)
ã®ããã«é¢æ°ã宣è¨ãã¦ããã¨ï¼ã³ã³ãã¤ã«å¾ã¯
(function() { myFunction = function (arg) { console.log(arg); }; }).call(this);
ã®ãããªæãã§JSãçæãããï¼
ããã ã¨ä»ã®JavaScripté¢æ°ãªã©ããmyFunction
ãå¼ã³åºããã¨ãã§ããªãï¼
å¿
è¦ãªããã°ã©ã ãå
¨ã¦app.coffeeå
ã§æ¸ãã°åé¡ç¡ããï¼CoffeScriptãªé¨åã¯å°ãã«çãã¦ï¼ä»ã¯JSã§æ¸ãããã¨ããå ´åã«ã¯å°ãï¼ã°ãã¼ãã«é åãªã©ã«é¢æ°ãå®ç¾©ãã¦ããã°ï¼åç
§ãããã¨ã¯å¯è½ã«ãªãã®ã§
window.myFunction = (arg) -> console.log(arg)
ã®ããã«é¢æ°å®ç¾©ãã¦åãã ï¼