0

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.

1
  • 1
    There is a coffeescript compiler in coffeescript and coffeescript compiles to javascript, you can just compile that and use it Commented Dec 4, 2012 at 19:55

2 Answers 2

3

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' })
Sign up to request clarification or add additional context in comments.

Comments

0

This project called js2coffee looks exactly what you need

3 Comments

Tamas wants to go from CS to JS not the other way.
@LarryMaccherone, look at the tabs above on the page, there is double option for both of ways
isn't the CS to JS way the same as using the CS transpiler?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.