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.

10,207 thoughts on “Using RequireJS exports with CoffeeScript

  1. fast withdrawal casino usa best crypto casinos 2021 (Gayle), free 10 no deposit casino usa and real online casino australia, or free casino money united states

  2. Terrific work! This is the type of information that are
    meant to be shared across the web. Shame on Google for not positioning this publish higher!
    Come on over and seek advice from my web site . Thank you
    =)

  3. What’s up to every , for the reason that I am actually eager of
    reading this weblog’s post to be updated daily. It includes nice stuff.

  4. What i don’t realize is in reality how you are no longer really much more well-liked than you may be right now.
    You’re so intelligent. You recognize therefore considerably in terms of this topic, made me personally consider it from numerous numerous
    angles. Its like women and men aren’t fascinated except it is something to accomplish with Girl gaga!
    Your personal stuffs nice. Always maintain it up!

  5. Do you have a spam problem on this site; I also am a blogger, and I was wanting to
    know your situation; we have developed some nice practices and we are
    looking to swap solutions with others, why not shoot me an email if interested.

  6. 당신의 멋진 포스팅에 감사합니다! 저는 정말 즐겼습니다, 당신은 훌륭한 작가가
    될 수 있습니다. 블로그를 북마크하고 앞으로 다시
    올 것입니다. 훌륭한 작업을 계속 이어가길 바랍니다, 멋진 날 되세요!

    I loved as much as you will receive carried out right here.
    The sketch is tasteful, your authored subject matter stylish.

    nonetheless, you command get got an impatience over that you wish be delivering the following.
    unwell unquestionably come more formerly again as exactly the
    same nearly very often inside case you shield this
    increase.

  7. Howdy! Quick question that’s completely off topic. Do you know how
    to make your site mobile friendly? My blog looks weird when browsing
    from my iphone4. I’m trying to find a theme or plugin that might be able to fix
    this problem. If you have any recommendations, please share.
    With thanks!

  8. Hello there! I could have sworn I’ve been to this blog before but after checking through some of the post I realized it’s new to me.
    Anyways, I’m definitely delighted I found it
    and I’ll be bookmarking and checking back frequently!

  9. Terrific post however I was wanting to know if you could write a litte more on this
    subject? I’d be very grateful if you could elaborate
    a little bit further. Thanks!

  10. Awesome blog! Is your theme custom made or did you download it from somewhere?
    A theme like yours with a few simple adjustements would really make my blog shine.
    Please let me know where you got your theme. Thank you

  11. Hello to every body, it’s my first pay a
    quick visit of this weblog; this weblog includes amazing and genuinely good stuff designed
    for visitors.

  12. This is a very good tip particularly to those fresh to the blogosphere.

    Short but very precise information… Thank you for sharing this
    one. A must read post!

  13. I’ve been exploring for a little bit for any high-quality articles or blog posts
    in this kind of space . Exploring in Yahoo I finally stumbled upon this web
    site. Studying this information So i’m glad to exhibit that I have a very excellent uncanny feeling I found out exactly what I needed.
    I most for sure will make sure to do not put out of
    your mind this site and give it a glance on a continuing basis.

  14. Every weekend i used to visit this web page, because i want enjoyment, since this this website conations in fact good
    funny information too.

  15. I know this if off topic but I’m looking into starting my own weblog and
    was wondering what all is required to get setup?
    I’m assuming having a blog like yours would cost a pretty
    penny? I’m not very web savvy so I’m not 100% sure.
    Any tips or advice would be greatly appreciated. Many thanks

  16. Great site you’ve got here.. It’s hard to find good quality writing like yours these days.
    I truly appreciate individuals like you! Take care!!

  17. I believe this is among the so much significant information for me.

    And i’m happy reading your article. But want to statement on some common issues,
    The site taste is perfect, the articles is truly excellent
    : D. Good job, cheers

  18. Definitely believe that which you said. Your favorite reason appeared to be on the internet the easiest thing to be
    aware of. I say to you, I certainly get irked while people consider worries that they
    just don’t know about. You managed to hit the nail upon the top and also defined
    out the whole thing without having side effect , people could take a signal.

    Will probably be back to get more. Thanks

  19. Its like you read my mind! You seem to know so much about this, like you wrote the book in it or
    something. I think that you can do with a few pics to drive the message home a bit,
    but instead of that, this is excellent blog.
    An excellent read. I’ll certainly be back.

  20. I all the time emailed this weblog post page to all
    my associates, because if like to read it then my friends will too.

  21. Link exchange is nothing else but it is only placing the other person’s weblog link on your page at appropriate place and other person will also do similar
    in support of you.

  22. дизайн интерьера в санкт петербурге дизайн интерьера питер

  23. Asking questions are truly pleasant thing if you are not understanding
    something totally, but this article provides nice understanding even.

  24. Thanks , I have recently been searching for information about this subject for ages and yours is the greatest I’ve came
    upon so far. However, what concerning the bottom line?

    Are you certain concerning the supply?

  25. This is a very informative post about online casinos and betting platforms.
    I especially liked how it explains the importance of choosing a licensed
    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.

  26. I’ve been surfing online more than 2 hours today, yet I never found any interesting article like
    yours. It is pretty worth enough for me.

    Personally, if all webmasters and bloggers made good content as you did, the net will be
    a lot more useful than ever before.

  27. It’s actually very complex in this full of activity life to listen news on Television, so I
    simply use web for that reason, and get the latest news.

  28. Aw, this was a very nice post. Taking the time and actual effort
    to make a really good article… but what
    can I say… I put things off a lot and don’t manage to
    get nearly anything done.

  29. Тензоприбор предлагает калибровочные гири для весов нужного класса точности и номинальной массы для калибровки весов.
    В нашей компании можно купить эталонные гири классов точности E1, E2, F1, F2, M1, M2.
    Чем выше класс точности, тем меньше будет разница между номинальным и действительным значениями массы калибровочной гири.

  30. united states online live casino, best canadian no
    deposit casinos and canada best slot machine, or best
    rated united kingdom online casino

    My web page – is there european roulette in vegas (Jacquelyn)

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>