1

If I wanted to port an existing project from Javascript to Coffeescript (in my case, within a Rails application), would I need to convert existing Javascript files? I'm worried about converting really large and CDN hosted files like jQuery and jQueryUI. How would I work around that?

3
  • 4
    What are you talking about? Why in the world would you need to rewrite jQuery/Ui into coffeescript? Commented Oct 23, 2012 at 21:48
  • 2
    CoffeeScript is for your own code, not third-party libraries... Commented Oct 23, 2012 at 21:50
  • See the comments on @Chris Peters answer. Commented Oct 23, 2012 at 22:16

2 Answers 2

5

As @asawyer stated, you do not need to port existing JavaScript libraries and such to CoffeeScript.

CoffeeScript exists to add convenience for writing your own custom code. Because the CoffeeScript compiles into JavaScript, it plays nicely with other JavaScript libraries like jQuery without your needing to convert those libraries into CoffeeScript.

If you have your own code that you want to convert into CoffeeScript, I've found js2coffee.org very helpful. It also serves as a great learning tool for "thinking in JavaScript" and seeing how it would be done in CoffeeScript.

Sign up to request clarification or add additional context in comments.

4 Comments

That makes a lot of sense, thanks Chris! I was worried that if I included coffeescript in my app then it would force all Javascript code to become coffeescript.
You're welcome. It was an interesting question. Don't pay attention to the hater in the question's comments.
As coffeescript.org puts it, 'The golden rule of CoffeeScript is: "It's just JavaScript".'
Oh I'm not worried about them. How dare I ask a question to a Q/A community. Silly of me... :)
0

Within rails, coffeescript is run through a compiler and into javascript anyway. You can include pure javascript files if you want (.js), or coffeescript (.js.coffee), which is compiled into js. If you're just looking to include legacy files, you won't need to do any conversion at all -- Might not make sense to convert to coffeescript, just to have rails compiler convert back to javascript in the asset pipeline... See http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets for more from the rails team on how to use js in the asset pipeline.

jQuery is already included in newer versions of Rails (3.1 onward), so that shouldn't be an issue. http://weblog.rubyonrails.org/2011/4/21/jquery-new-default/

Also, many other jQuery addons have a gem that you can simply include -- no need to reinvent the wheel there.

Comments

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.