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.

19,381 thoughts on “Using RequireJS exports with CoffeeScript

  1. В этой медицинской статье мы погрузимся в актуальные вопросы здравоохранения и лечения заболеваний. Читатели узнают о современных подходах, методах диагностики и новых открытий в научных исследованиях. Наша цель — донести важную информацию и повысить уровень осведомленности о здоровье.
    Прочесть заключение эксперта – Наркологическая клиника «Похмельная служба» в Казани.

  2. В этой публикации мы предложим ряд рекомендаций по избавлению от зависимостей и успешному восстановлению. Мы обсудим методы привлечения поддержки и важность самосознания. Эти советы помогут людям вернуться к нормальной жизни и стать на путь выздоровления.
    Узнай первым! – Похмельная служба Казань

  3. We stumbled over here different website and thought I might as well
    check things out. I like what I see so now i’m following you.
    Look forward to looking at your web page repeatedly.

  4. Way cool! Some extremely valid points! I appreciate you penning this write-up and the rest
    of the site is extremely good.

  5. Tava evitando Raider Jane’s Crypt of Fortune depois do patch, voltei essa semana, mesmo clima de antes.

  6. I blog quite often and I really thank you for your information. The article has
    really peaked my interest. I will bookmark your Web Site and keep checking for new information about once a week.

    I opted in for your Feed too.

  7. krabi tipa resort 4 краби ао нанг пляж клонг муанг краби отзывы

  8. где научиться кайтсерфингу learn to kite Hurghada

  9. An outstanding share! I’ve just forwarded this onto a friend who was
    conducting a little research on this. And he in fact ordered
    me breakfast simply because I stumbled upon it for him…
    lol. So allow me to reword this…. Thanks for
    the meal!! But yeah, thanx for spending some time to talk about this
    matter here on your website.

  10. I’ve been exploring for a bit for any high-quality articles or weblog posts in this kind
    of house . Exploring in Yahoo I eventually stumbled upon this web site.
    Reading this information So i’m satisfied to show that I have
    an incredibly excellent uncanny feeling I discovered just what I needed.
    I so much without a doubt will make certain to don?t omit this site and provides it a look regularly.

  11. It’s really a great and useful piece of info.

    I’m glad that you shared this helpful information with us.
    Please stay us up to date like this. Thanks for sharing.

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

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

  14. I’ll never forget the moment I stumbled onto a fresh online casino site that
    instantly felt more immersive than the usual ones.

    To be fair, I wasn’t planning to stay long, but the enormous game catalog — more than enough choices to last a lifetime — caught my attention.

    Getting a matched deposit + a pile of spins felt surprisingly generous, and after
    making the first deposit, I finally understood why people talk about good bonuses.

    The requirements weren’t exactly relaxed, but it felt fair considering the
    size of the bonus.

    What really caught me emotionally was how smooth the withdrawals were.

    Soon after requesting, the funds were already processed, and that gave me a sense of trust.

    The VIP program was another unexpected thing.

    I never cared much for VIP stuff, but the cashback percentages actually felt meaningful.

    Getting back a portion of my losses made my sessions less stressful, and I actually enjoyed the grind.

    The game variety overwhelmed me at first — in a good way.

    Whether I felt like slow strategic play or chaotic spinning,
    I found it.
    Sometimes I’d switch from roulette to video slots,
    and I never ran out of choices.

    What also surprised me was how many payment methods they supported.

    For me, fast transactions matter, so the crypto support made
    the whole experience feel modern.

    Of course, it wasn’t perfect.
    Some game info wasn’t detailed.
    And I had to search around for regulatory info.
    But emotionally?
    The good outweighed the bad for me.

    If you’re reading this because you’re curious, from my own experience —
    I found real entertainment value here.
    And yes, I dropped a comment link below, so you can explore
    it yourself.

  15. Howdy! I’m at work surfing around your blog from my
    new apple iphone! Just wanted to say I love reading
    through your blog and look forward to all your posts!
    Carry on the outstanding work!

  16. Thanks a bunch for sharing this with all people you really recognize what
    you’re speaking about! Bookmarked. Please additionally
    discuss with my site =). We could have a link change contract between us

  17. After looking into a number of the blog posts on your web page, I seriously like your
    technique of blogging. I book-marked it to my
    bookmark website list and will be checking back soon. Please check out
    my website too and tell me your opinion.

  18. First of all I want to say wonderful blog! I had a
    quick question which I’d like to ask if you don’t mind.
    I was interested to find out how you center yourself and clear your head
    before writing. I have had a hard time clearing my thoughts in getting my ideas out there.
    I do enjoy writing however it just seems
    like the first 10 to 15 minutes are generally wasted simply just trying to figure out how to begin. Any ideas or tips?
    Many thanks!

  19. Undeniably imagine that that you stated. Your favorite justification appeared to be
    on the web the easiest thing to have in mind of.
    I say to you, I certainly get irked while folks think about
    concerns that they just don’t realize about. You controlled to
    hit the nail upon the highest as smartly as outlined
    out the whole thing with no need side-effects , folks can take a signal.

    Will likely be back to get more. Thank you

  20. I am actually delighted to read this web site posts which includes plenty of useful facts, thanks for providing
    these kinds of statistics.

  21. Sweet blog! I found it while searching on Yahoo News.

    Do you have any suggestions on how to get listed in Yahoo News?

    I’ve been trying for a while but I never seem to get there!
    Appreciate it

  22. I am really loving the theme/design of your site. Do
    you ever run into any internet browser compatibility problems?
    A couple of my blog readers have complained about
    my blog not working correctly in Explorer but looks great in Chrome.
    Do you have any advice to help fix this issue?

  23. Very nice post. I just stumbled upon your blog and wanted to say that I have really enjoyed surfing around your blog posts.
    After all I will be subscribing to your rss feed and I hope you write
    again soon!

  24. Этот документ охватывает важные аспекты медицинской науки, сосредотачиваясь на ключевых вопросах, касающихся здоровья населения. Мы рассматриваем свежие исследования, клинические рекомендации и лучшие практики, которые помогут улучшить качество лечения и профилактики заболеваний. Читатели получат возможность углубиться в различные медицинские дисциплины.
    Что ещё? Расскажи всё! – Наркологическая клиника «Похмельная служба» в Мытищах

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>