I don't know whether all coffeescript compilers wrap their scripts in anonymous functions, but that's what I see Rails doing. How can I disable this encapsulation?
I want to put several initializing functions in a single coffeescript file, then call one of them from an on-page <script>
tag (so that each page calls a different initializer). This can't be if the initializing functions are encapsulated.
Coffeescript initializer functions:
initializerA = -> console.log 'foo'
initializerB = -> console.log 'bar'
On-page code:
<script>$(document).ready(initializerA)</script>
Sys: coffee-rails 3.2.1, Rails 3.2.3, Ruby 1.9.3
Coffeescript documentation says that all script will be wrapped in an anonymous function for the sake of encapsulation/safety. To make something accessible within the global scope do the following:
window.myvar = myvar
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