Your function square has to be a globally defined function in order to call it from your HTML like you have defined. But this block of code:
(function() {
var square;
square = function(x) {
return alert(x * x);
};
}).call(this);
Does not define the function globally, therefore the symbol can't be found. In fact, the function square is only defined within your IIFE and isn't available anywhere else. If you want it available globally, you may as well just change the above block to this:
window.square = function(x) {
return alert(x * x);
}
Or, you could do this:
(function() {
this.square = function(x) {
return alert(x * x);
};
}).call(this);
Or, apparently in CoffeeScript, the @ sign is a shorthand for this.
so you can use this:
(function() {
@square = function(x) {
return alert(x * x);
};
}).call(this);
or even just this:
@square = function(x) {
return alert(x * x);
};
See this other answer for more info: How do I define global variables in CoffeeScript?
Even better would be to not use this calling method. If you use event listeners instead, then you don't have to make the function be global at all.