I found that to be rather misleading as I thought it suggest that such files could include a mixture of both javascript and coffeescript code. Is there something very fundamental that I am missing?
CoffeeScript is a programming language that compiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python, and Haskell in an effort to enhance JavaScript's brevity and readability. Specific additional features include list comprehension and destructuring assignment.
JavaScript file written in CoffeeScript, a programming language that compiles and transcompiles to JavaScript; saved in a text format and contains code that is similar to JavaScript, but modified to be more readable. CoffeeScript's aim is to enhance JavaScript's brevity and readability.
CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way. The golden rule of CoffeeScript is: “It's just JavaScript.” The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime.
It's a common practice in Rails for templates to have extensions like .js.coffee
, .html.erb
, .html.haml
, etc.
If I remember correctly Rails interprets these extensions as .[format].[builder]
and uses that knowledge to do two things:
[format]
value comparing it with acceptable formats listed in the request's Accept
header;[builder]
value to parse your template.And you can include plain javascript if you use backticks.
Something like `function(){ do something };`
would work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With