0

While bare compiling CoffeScript to better understand it, I started wondering how I can write the wrapper function

(function(){

}).call(this)

using CoffeScript.

I know I could just compile it the way it is supposed to, but I'm curious.

1 Answers1

0

Compiling:

console.log('Try');

in CoffeeScript 1.6.3 gives:

// Generated by CoffeeScript 1.6.3
(function() {
  console.log('Try');

}).call(this);

Try here: http://www.compileonline.com/try_coffeescript_online.php

or if you'd rather have the bare one, compile:

#blank

gives:

// Generated by CoffeeScript 1.6.3
(function() {


}).call(this);

In case the --bare option is turned on, you can use:

( -> ) .call(this)

which gives:

(function() {}).call(this);

Try it here: http://coffeescript.org/ (Try coffee tab.)

Sunny R Gupta
  • 5,026
  • 1
  • 31
  • 40
  • you might wanna check the -b option [here](http://coffeescript.org/documentation/docs/command.html) –  Jun 09 '14 at 10:32
  • `$coffee -c -p main.coffee` is what I am using – Sunny R Gupta Jun 09 '14 at 10:36
  • yeah, and that works but if you add -b (`$coffee -c -b -p main.coffee`) it omits the wrapper function. And that's what I am doing. –  Jun 09 '14 at 10:40
  • but that would only make sense if you want to do something within it. – Sunny R Gupta Jun 09 '14 at 10:41
  • http://coffeescript.org/ - if you see here, the first example generates it. But only because it is used as an IIFE. – Sunny R Gupta Jun 09 '14 at 10:43
  • Not really. While learning a new language you should explore all the functions and features. I won't probably need nor use that, but that does not mean I'm relieved from knowing it. –  Jun 09 '14 at 10:49
  • :) I understand. Answer updated to include case where --bare option is enabled. – Sunny R Gupta Jun 09 '14 at 11:02