Using RequireJS exports with CoffeeScript

If you are using the “exports” object in your RequireJS module definition and happen to also be using CoffeeScript then be careful to either return the exports object at the end of the function or explicitly return nothing from the function by typing “return” on the last line. Like so:

define((require, exports, module) ->
    exports.foo = 'bar'
    return
)

If you don’t return nothing or the exports object CoffeeScript will compile this:

define((require, exports, module) ->
    exports.foo = 'bar'
)

…to the following javascript:

define(function(require, exports, module) {
    return exports.foo = 'bar';
});

Where the return value will be the string ‘bar’. This is no good because if you return a value from your module definition function, RequireJs uses it instead of the exports object. So when you come to require your module, you’ll be passed a String, rather than an object with a “foo” property as you’d expect.

17,698 thoughts on “Using RequireJS exports with CoffeeScript

  1. This is a well-written post about online casinos. I found it useful how
    you explained the importance of choosing reliable sites.

    From what I’ve seen, UFABET888 are frequently mentioned because they have smooth systems and quick payouts.

    Many users often struggle to find safe betting
    sites, so content like this is great for guidance.

    Thanks for sharing — this will definitely help new
    users choose better platforms.

  2. I like the helpful info you provide in your articles.
    I’ll bookmark your weblog and check again here frequently.
    I am quite sure I will learn many new stuff right here!
    Good luck for the next!

  3. This is a very informative post about online casinos and betting platforms.

    I especially liked how it explains the importance of choosing a secure
    site before signing up.

    Many players often ask where they can find reliable gaming platforms with
    fair odds and smooth payouts. From what I’ve seen,
    checking platforms like vn22vip helps users compare features, bonuses,
    and overall experience.

    Thanks for sharing these insights — they’re helpful for both beginners and experienced bettors.

  4. Thanks for finally talking about > Using RequireJS exports with CoffeeScript | freestyle developments
    < Liked it!

  5. Hi there! Do you use Twitter? I’d like to follow you if that would be ok.

    I’m absolutely enjoying your blog and look forward to new
    updates.

  6. Excellent blog here! Also your web site loads up fast!

    What web host are you using? Can I get your affiliate link to your host?
    I wish my website loaded up as fast as yours lol

  7. Hi! Someone in my Myspace group shared this site with
    us so I came to take a look. I’m definitely enjoying the information. I’m book-marking and will be tweeting this to
    my followers! Superb blog and brilliant design and style.

  8. В этом обзоре представлены различные методы избавления от зависимости, включая терапевтические и психологические подходы. Мы сравниваем их эффективность и предоставляем рекомендации для тех, кто хочет вернуться к трезвой жизни. Читатели смогут найти информацию о реабилитационных центрах и поддерживающих группах.
    Что скрывают от вас? – медицинский наркологический центр

  9. В этой статье рассматриваются актуальные вопросы, связанные с развитием медицинской науки и её внедрением в повседневную практику. Особое внимание уделено вопросам профилактики, ранней диагностики и использованию технологий для улучшения здоровья человека.
    Прочесть заключение эксперта – наркологический центр нижний новгород

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>