Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoffeeScript function created in app/assets/javascript not found

Tags:

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?

like image 346
revolver Avatar asked Jul 13 '12 04:07

revolver


2 Answers

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) -> 
like image 59
SMathew Avatar answered Nov 03 '22 00:11

SMathew


Bind it to the window

myFunction = (variable) ->   alert('zzzzzzzz')  window.myFunction = myFunction 
like image 20
house9 Avatar answered Nov 02 '22 22:11

house9