ãããªè¨³ã§ãCoffeeScript ã触ãå§ãã¦åå¹´å¼±ãTypeScript ã触ãå§ãã¦1ã¶æå¼±ã»ã©çµã¡ã¾ãããã¾ã ã¾ã æ¥ã¯æµ ãã§ããããã¡ãã両æ¹ã¨ãå®åæ¡ä»¶ã«ã¦ä½¿ç¨ããã¨ãããã¨ã§ããããã§åæ¹ã«å¯¾ããæ¯ãè¿ããç°¡åã«ãã¦ããã¨ãã¾ãã CoffeeScript ã«ã¤ã㦠http://coffeescript.org/ å¦ç¿éå§ææ: 2014å¹´1æé å§ãããã£ãã: Middleman ã Ruby on Rails ãæ¨æºãµãã¼ããã¦ãããããé¢åãªç°å¢æ§ç¯çãããªãã¦æ¸ãã ãã Ruby ã Haml ã®ãããªããã¹ãéã®å°ãªãææ³ã好ã¿ã ã£ããã ãããªè¨³ã§ã¨ã£ãããã¨ãã¦ã®åºç¤å¦ç¿æéã¯ã ããã2ãï¼æ¥ãããã§ãããããæ¢åã®ãããã¯ã·ã§ã³ã³ã¼ãã CoffeeScript ã«æ¸ãæãã¤ã¤å®æ¡ä»¶ã«åãå ¥ãã¦ããã¾ããã ããã¾ããªç¹å¾´ è¦ã¯ JavaScript ãã
åæ ä¼ç¤¾(Quipper)ã§ä»ãããããã風ã«ããããã¨å®£è¨ãã社å ããã¥ã¡ã³ããå ¬éããã æ¯ãã¦ãããã§ã¯ãªãã coffeescript Backbone Backbone.stickit (ãã¼ã¿ãã¤ã³ãã£ã³ã°) Chapling.js(ã¯ããªãã±ãªã®ã§ã©ãã§ãããããµã³ãã«ã³ã¼ãã¯ãã) backbone.stickitã¯å®å¿ã¨ä¿¡é ¼ã®NYT製ã(å®è³ªBackboneä½ã£ã¦ãDocumentCloudã¨ä¸ç·ã®ã¨ãã?) backbone.stickit ç®ç ãã¼ã¿ãã¤ã³ãã£ã³ã°ãå ¨é¢çã«ä½¿ã£ã¦åæç»ãæå°éã«ããã³ã¼ãã®è¦éãããããããã ã¢ãã«ã®å½¹å²ãæ示çã«ããMVVMãå°å ¥ããã çæ³çãªAPI æ¬ä¼¼ã³ã¼ã # ãã¥ã¼ã¢ãã«ã®å®ç¾© class TopicViewModel extends Model defaults: title: '' # ãã¶ãããã§ãã©ã¡ã¼ã¿å(
CoffeeScriptã®é¢æ°ã¯æ示çã«returnããã¹ã | CreativeStyle æ¬å½ã«é ãã®ããããã確ããã¾ãããã é©å½ã«ã§ã£ã¡ãããã³ã¼ãã§ã f1 = -> for i in [1, 2, 3] for j in [4, 5, 6] i + j f2 = -> for i in [1, 2, 3] for j in [4, 5, 6] i + j return console.time "f1" for i in [1..100000] then f1() console.timeEnd "f1" console.time "f2" for i in [1..100000] then f2() console.timeEnd "f2" å®è¡ãã¦ã¿ã¾ã $ coffee hoge.coffee f1: 105ms f2: 4ms ç´26åéããã¨ãããã¨ããããã¾ãã
ããã«ã¡ã¯ã æ¼å¤é転ãä¸å¨ãã¦ãã£ã¨æ®éã®çæ´»ã«æ»ã£ã¦æ¥ã¾ãããããã§ã æè¿ãCoffeeScriptã¨ããJavaScriptã®ã©ã¤ãã©ãªã«ããã£ã¦ãã¾ãã åå¹´åãããã«æµè¡ã£ããè³å¦ä¸¡è«ãªjsã©ã¤ãã©ãªã§ãã é常ã«ã·ã³ãã«ã«jsãæ¸ããã¨ãã§ãã¦ãRuby on Railsã§ãå ¬å¼æ¡ç¨ããã¦ãã¾ãã ãã®CoffeeScriptã§jQueryã®ãã©ã°ã¤ã³ãï¼ã¤æ¸ãã¦ã¿ã¦ãCoffeeScriptã§éçºãã¦ãããã¨ã«ã¤ãã¦æãããã¨ãã¡ã¢ãã¾ãã CoffeeScriptãjQueryãã©ã°ã¤ã³ã®åºç¤ã«ã¤ãã¦ã¯ç¹ã«è§¦ãã¾ããããäºæ¿ä¸ããã CoffeeScriptã¨ã¯ CoffeeScriptã¯JavaScriptã楽ã«ã·ã³ãã«ã«æ¸ããã©ã¤ãã©ãªã§ããããã¾ããªç¹å¾´ã¯ã ææ³ã¯RubyãPythonã«è¿ã é¢æ°å¼ã³åºãã®éã«å¼æ°ã®æ¬å¼§ãçç¥ã§ãã ã¤ã³ãã³ãã§ã«ã¼ããé¢æ°ãªã©ã®
Rails ã® Asset Pipeline 㯠CoffeeScript ãã³ã³ãã¤ã«ãã¦ããããã©ãSourceMaps ã¯çæãã¦ãããªãã ãã£ãã Chrome ã SourceMaps ããµãã¼ããã¦ããã¨ããã®ã«ãæªã ã«çæããã JavaScript ã³ã¼ãã§ãããã°ããã¨ããã®ãã å®ã¯ããæ¢ã« SourceMaps ãçæã§ããããã«ãªã£ã¦ãããã¨ãæå¾ ãã¦ãcoffee-rails ã®ã¤ã·ã¥ã¼è¦ã¦ã¿ã㨠Support for source maps · Issue #40 · rails coffee-rails Sprockets ã®å¯¾å¿å¾ ã¡ã¨ããã ããæã£ã人ãããããã§ãcoffee-rails ã®ã¢ã³ãã¼ãããã gist ã§å ¬éãã¦ããã Monkey patch for Coffee Script v.1.6.1 Source Maps for Rai
CoffeeScriptã§ã¯ãã¯ã©ã¹å ã®å¤æ°ã«ã@ããã¤ãã¦å®£è¨ããã¨ã¯ã©ã¹ã¡ã½ããã«ãªãã ä¾class Hoge #ã¯ã©ã¹ã¡ã½ãã @classMethod = (param) -> "param is #{param}." #ã¯ã©ã¹å¤æ° @count = 0 constructor: -> # ã³ã³ã¹ãã©ã¯ã¿å ã§ãã¯ã©ã¹å¤æ°ã®å¤ãã¤ã³ã¯ãªã¡ã³ã Hoge.count += 1; console.log Hoge.classMethod "ãã©ã¡ã¼ã¿" new Hoge(); console.log Hoge.count new Hoge(); console.log Hoge.count å®è¡çµæparam is ãã©ã¡ã¼ã¿. 1 2 JavaScriptã¸ã®å¤æçµæã¯ã©ã¹ã¡ã½ãããå¤æ°ã¯ãCoffeeScriptã§å®ç¾©ããã¯ã©ã¹ã«å¯¾å¿ããfunctionã®ããããã£ã¨ãã¦å®£è¨ããã
ãªãã§ãããã¨è©±ãã¦ããããã©ããããã³ã³ãã¤ã«ããã¹ã¯ãªããã«ã¦ããã¦ããã®å¤æ°ã使ããã¦ããã != nullçããã以å¤ã¯typeofçãã«ãªãã£ã½ãã ã¾ãã age != null ã®ãã§ãã¯ã¯ãage ã undefined ããnull ã®å ´åã«ã®ã¿ false ãè¿ãããããè¦ããã«ä½ãã»ããããã¦ãããããã§ãã¯ãããã¾ãæ¸ãæ¹ãããã ã§ãããããªã㧠typeofããã¡ãã ã£ã¦ããé·ããã¤ã«ãªããã£ã¦è¨ãã¨ããã®å¤æ°ãã¾ã 使ããã¦ããªãã£ãå ´åãif (age != null) ã§ãã§ãã¯ãã¡ããã¨ãage is undefined ã¨ãã¨ã©ã¼ãè¿ããã¦ãã¾ããããã typeof age ã¨ããã°ãå¤æ° age ã宣è¨ããã¦ããªãå ´åã§ããã¨ã©ã¼ãåºãªãã
ããæ¹ å®ç¾©ã®éã«@ãé ã«ä»ããã class Something someProp: "hoge" someMethod: -> ... @someClassProp: "HOGEHOGE" @someClassMethod: -> ... ã©ããã£ã¦ãããã ããã¨æ¢ãããããã¥ã¡ã³ãã«è¿½è¨ã£ã½ãã¡ããã£ã¨æ¸ãã¦ãã£ãã object itself (the constructor function), you can assign static properties by using @property: value, and call functions defined in parent classes: @attr âtitleâ, type: âtextâ ã¾ãããã¥ã¡ã³ãèªä½ãã¡ãã£ã¨è§£èª¬ã®ã¤ãããã¼ãã·ã¼ãã¿ãããªå ·åãªã®ã§ããããããªãã¨ãã¡ããã£ã¨æ¸ãã¦ããã Java
CoffeeScriptã¨ã¯? Ajaxã®æ®åã«ä¼´ã£ã¦åºãå©ç¨ãããããã«ãªã£ãJavaScriptã ãã大è¦æ¨¡ãªã¢ããªã±ã¼ã·ã§ã³ã®éçºã«åãã¦ããªããã¨ãããã©ã¦ã¶ãã¨ã®æ©è½ãæåã®éããªã©ãæ§ã ãªåé¡ãæ±ãã¦ããã®ã¯å¨ç¥ã®äºå®ã ã ãããã®åé¡ã解決ããããã«æ§ã ãªæè¡ãç»å ´ãã¦ãã¦ãããããªãã§ãç®ãå¼ãã®ãæ¬é£è¼ã§ãç´¹ä»ããTypeScriptãªã©ãJavaScriptã®ä»£æ¿ã¨ãªãæ°ããªããã°ã©ãã³ã°è¨èªãã¡ã ããããã®è¨èªã¯ã³ã³ãã¤ã©ã«ãã£ã¦JavaScriptã³ã¼ãã«å¤æããã¦å®è¡ããããããå®è¡æã«ç¹å¥ãªã½ããã¦ã§ã¢ãå¿ è¦ã¨ããªãã¨ããç¹å¾´ãããã CoffeeScriptããããã®JavaScript代æ¿è¨èªã®ã²ã¨ã¤ã§ãã·ã³ã¿ãã¯ã¹ã·ã¥ã¬ã¼ããã¿ã¼ã³ãããã«ãã£ã¦JavaScriptã¨æ¯ã¹ã¦ç°¡æ½ã«ã³ã¼ããè¨è¿°ãããã¨ãã§ãããCoffeeScriptã¯ãJavaScript
stockNum.App Something new is just around the corner ðð
JavaScriptãæé©åãã CoffeeScriptãJavaScriptã«ã³ã³ãã¤ã«ããããæ¬çªç°å¢ã®ãµã¼ãã«é ç½®ããåã«æé©åãè¡ã£ã¦ããã¨ããã§ããããããã§ããæé©åã¨ã¯ã空ç½ãªã©ã®ä¸è¦ãªé¨åãåãé¤ããããå¤æ°åãçãååã«ç½®ãæãã¦ãã¡ã¤ã«ãµã¤ãºãæ¸ããå¦çãããã¾ããæé©åãããã¨ãã½ã¼ã¹ã³ã¼ãã®æåãå ¨ãå¤ããã«ãã¡ã¤ã«ãµã¤ãºãæ¸ãããã¨ãã§ãã¾ãã UglifyJSï¼BSDã©ã¤ã»ã³ã¹ï¼ã¨ããæé©åãã¼ã«ã¯ãYUI Compressorï¼Yahoo!ãéçºããJavaScriptæé©åãã¼ã«ï¼ãGoogle Closure Compilerï¼GoogleãéçºããJavaScriptæé©åãã¼ã«ï¼ãªã©ã®ä»ã®æé©åãã¼ã«ã¨æ¯ã¹ã¦å®è¡é度ã¨å§ç¸®å¹çã®é¢ã§é常ã«ãã©ã³ã¹ãããåãã¦ãã¾ããYUI Compressorã¨æ¯ã¹ãå ´åãUglifyJSã®æ¹ãå§ç¸®å¹çã¯å¤§å¹ ã«è¯ãã
CoffeeScriptã§Classãä½ã£ãå ´åããã®ã¯ã©ã¹ãã°ãã¼ãã«ããåç §åºæ¥ãªãããããæã£ãã ä¾ãã°ã class Hoge constructor: (@param) -> @name = @param.name setName: (name) -> @name = name getName: -> @nameãã®CoffeeScriptãã³ã³ãã¤ã«ããã¨ä»¥ä¸ã®ãããªJSãã¡ã¤ã«ãåºåãããã (function() { var Hoge; Hoge = (function() { function Hoge(param) { this.param = param; this.name = this.param.name; } Hoge.prototype.setName = function(name) { return this.name = name; }; Hoge.
CoffeeScriptã§å³æé¢æ°ã¯æ¸ããªãã®ããªã¼ã¨æã£ã¦ãããã試ãã¦ã¿ããæ¸ããã ç°å¢ï¼CoffeeScript 1.1.1 (-> console.log 1 return )() ()ã§å²ãã§ããã°ããã®ãã 追è¨ï¼ id:murky-satyrããã«ã³ã¡ã³ãã§æãã¦ããã£ãï¼ do -> console.log 1 return æåã«æ¸ããæ¹ã¯CoffeeScriptãªã®ã«ã·ã³ãã«ãªæ¸ãæ¹ãããªããªã¼ãã¨æã£ã¦ãããã¾ãã¾å³æé¢æ°ã¨ãã¦è§£éããã¦ãã ãã ã£ãã¿ããï¼ å ¬å¼ã«æ¸ãã¦ããã¨ããã CoffeeScript provides the do keyword, which immediately invokes a passed function, forwarding any arguments.ãããããªâ¦â¦ï¼ 追è¨2ï¼ å³æé¢æ°ã«å¼æ°ã渡ãå ´åã¯æåã«æ¸ããæã
ãç¥ãã
é害
ã©ã³ãã³ã°
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}