On Coffeescript.org:
bawbag = (x, y) ->
z = (x * y)
bawbag(5, 10)
would compile to:
var bawbag;
bawbag = function(
To me it seems @atomicules has the simplest answer, but I think it can be simplified a little more. You need to put an @
before anything you want to be global, so that it compiles to this.anything
and this
refers to the global object.
@bawbag = (x, y) ->
z = (x * y)
bawbag(5, 10)
this.bawbag = function(x, y) {
var z;
return z = x * y;
};
bawbag(5, 10);
(function() {
this.bawbag = function(x, y) {
var z;
return z = x * y;
};
console.log(bawbag(5,13)) // works here
}).call(this);
console.log(bawbag(5,11)) // works here
To add to Ivo Wetzel's answer
There seems to be a shorthand syntax for exports ? this
that I can only find documented/mentioned on a Google group posting.
I.e. in a web page to make a function available globally you declare the function again with an @
prefix:
<script type="text/coffeescript">
@aglobalfunction = aglobalfunction = () ->
alert "Hello!"
</script>
<a href="javascript:aglobalfunction()" >Click me!</a>