In my CoffeeScript file, clients.js.coffee
,
myFunction = (variable) ->
I created a function in CoffeeScript in app/assets/javascript
. But when I try to call that function, the console shows me an error saying function not found.
I check the source of the page and it shows that the script is loaded:
<script src="/assets/clients.js?body=1" type="text/javascript"></script>
This is what was found inside the script source:
(function() { var myFunction; myFunction = function(variable) {} }).call(this);
Any idea what am I missing? What should I do to call the function?
To make it accessible from outside, all you need to do is add an '@' in front. This will attach the function to the window object.
@myFunction = (variable) ->
Bind it to the window
myFunction = (variable) -> alert('zzzzzzzz') window.myFunction = myFunction
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