Execution of the immediate function


CoffeeScript compiled this code:

mod = (num) -> num % 2


// Generated by CoffeeScript 1.7.1
(function() {
  var mod;

  mod = function(num) {
    return num % 2;


How can I call this JavaScript immediate function?

For example, I'd like to call mod.apply(5).

You can do this:

mod = ((num) -> num % 2) 5

That's not the same as mod.apply(5), which would not call the "mod" function such that "num" is 5. Instead it'd call the function such that this was 5, which I doubt is what you really wanted to do.

The result of my code above would be to set "mod" to 1, which is 5 % 2.

Now, if you just want to call "mod" later, you would use your original code and then just do it:

mod5 = mod 5