Rails 3.2.8. In converting some of my JS functions over to CoffeeScript, I have come across several questions that say declaring a function like so:
@foo = (bar) ->
puts foo in the global namespace. But it doesn’t, because my function calls elsewhere in the application, especially ones that are in .js.erb files.
Here’s what does work:
foo = (bar) ->
window.foo = foo
With that, all my calls in .js.erb files work fine.
What is the reason that the @foo = notation doesn’t work as I am expecting it to? That would be a lot easier than having to remember to add an extra line to expose the function to the global namespace.
@footranslates tothis.foofootranslates tovar fooThere is a big difference between the two of those.
For example:
Translates to:
See fiddle demo of generated code: http://jsfiddle.net/maniator/rXWw2/
Here is a link showing you the CoffeeScript and it’s generated code