benrady / modit

Javascript Modules with Superpowers
16 stars 1 forks source link

coffeescript incompatibility #2

Open amirrajan opened 12 years ago

amirrajan commented 12 years ago

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 commented 12 years ago

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