Is there a way to compile CoffeeScript to JavaScript code using JavaScript? User writes CoffeeScript code to a textarea (or a codemirror editor..), and I want to compile the coffee code to js and execute it.
I know how to compile coffee to js with php, or other server side languages but I want to do it on client side.
-
1There is a coffeescript compiler in coffeescript and coffeescript compiles to javascript, you can just compile that and use itBenjamin Gruenbaum– Benjamin Gruenbaum2012年12月04日 19:55:38 +00:00Commented Dec 4, 2012 at 19:55
2 Answers 2
Go to the CoffeeScript site and read the "text/coffeescript Script Tags" paragraph.
In fact, the little bit of glue script that runs "Try CoffeeScript" above, as well as the jQuery for the menu, is implemented in just this way. View source and look at the bottom of the page to see the example. Including the script also gives you access to CoffeeScript.compile() so you can pop open Firebug and try compiling some strings.
Don't forget the bare option, or else the compiled code will be wrapped
CoffeeScript.compile('alert "hello"', { bare: 'on' })
Comments
This project called js2coffee looks exactly what you need