modit icon indicating copy to clipboard operation
modit copied to clipboard

coffeescript incompatibility

Open amirrajan opened this issue 14 years ago • 1 comments

coffeescript does not allow for function declarations and I'm unsure of how to use it with modit given that.

for example, a valid module looks like the following in javascript:

modit('foobar', function() {
    function init() {
        alert('works');
    }

    this.exports(init);
}

you cannot generate the code above using coffeescript, follows is the coffeescript i used and the resulting javascript output:

    //coffee script
modit 'foobar', () ->
    init = (urls) -> alert('works')

    this.exports(init)

//compiles to
(function() {
  modit('foobar', function() {
    var init;
    init = function(urls) {
      return alert('works');
    };
    return this.exports(init);
  });
}).call(this);

I've tried different variations with no luck:

modit 'foobar', () ->
    init: (urls) -> alert('works')

    this.exports(init)

 (function() {
  modit('foobar', function() {
    ({
      init: function(urls) {
        return alert('works');
      }
    });
    return this.exports(init);
  });
}).call(this);   

amirrajan avatar Oct 17 '11 00:10 amirrajan

here is an additional link that may help clarify http://stackoverflow.com/questions/6548750/function-declaration-in-coffeescript

amirrajan avatar Oct 17 '11 00:10 amirrajan