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.

18,925 thoughts on “Using RequireJS exports with CoffeeScript

  1. I am not sure where you are getting your info, but great topic.
    I needs to spend some time learning more or understanding more.

    Thanks for fantastic info I was looking for this info for my mission.

  2. Hello! 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 posts.

  3. Hi! I know this is kinda off topic but I was
    wondering if you knew where I could find a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having
    difficulty finding one? Thanks a lot!

  4. Hey There. I found your blog using msn. This is an extremely well written article.

    I will make sure to bookmark it and return to read more of
    your useful information. Thanks for the post.
    I will definitely return.

  5. Hi there, just became alert to your blog through Google,
    and found that it is really informative. I’m gonna watch out for
    brussels. I’ll be grateful if you continue this in future.
    Lots of people will be benefited from your writing.

    Cheers!

  6. Wow, incredible weblog format! How long have you ever been blogging
    for? you made running a blog glance easy. The whole look of your website is great, let alone the content!

  7. I’m truly enjoying the design and layout of your site.
    It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did
    you hire out a developer to create your theme? Fantastic work!

  8. I read this piece of writing fully about the resemblance
    of most up-to-date and preceding technologies, it’s amazing
    article.

  9. Pretty nice post. I simply stumbled upon your weblog and wished to
    mention that I have truly loved surfing around your blog
    posts. After all I will be subscribing on your rss feed and I’m hoping you
    write once more very soon!

  10. Разработка интернет-магазина на 1С-Битрикс под ключ на шаблоне. Переходите по запросу создание интернет магазина на Битрикс и получите удобный, быстрый и продающий сайт с адаптивным дизайном, интеграцией CRM, оплатой и доставкой. Оптимизируем под SEO и помогаем увеличить продажи. Индивидуальный подход, прозрачные сроки и поддержка на всех этапах.

  11. Awesome issues here. I’m very glad to peer your post. Thank
    you so much and I’m taking a look forward to contact you.
    Will you kindly drop me a mail?

  12. We stumbled over here coming from a different page and thought I
    might as well check things out. I like what I see so i
    am just following you. Look forward to finding out about your
    web page again.

  13. Hi there all, here every one is sharing these kinds of experience, therefore it’s nice to read this webpage, and
    I used to visit this weblog daily.

  14. Do you mind if I quote a few of your posts as long as I provide
    credit and sources back to your weblog? My blog is in the
    very same niche as yours and my users would truly benefit from a lot of the
    information you provide here. Please let me know if this alright with
    you. Thanks a lot!

  15. Ijust wrote about how Jane chose Paybis to transfer her
    money from her bank into crypto and then straight into her trading account, and honestly, her whole story turned
    out way more fun than anyone thought.

    Jane isn’t your regular crypto newbie. Funny thing — she collects
    tiny vintage globes and has exactly 27 of them lined up behind her desk.

    Another fun fact is that she can solve a Rubik’s
    cube in under 40 seconds. So when she discovered Paybis, she approached
    it with the same energy — fast, efficient, and determined.

    As she told me, she wanted a platform that wouldn’t “fight her back,
    ” because her bank is already stressful enough.
    Paybis ended up being perfect: super user-friendly onboarding, easy deposit,
    and she was able to convert her bank funds into crypto
    in literally minutes. Jane even joked it was easier than ordering sushi.

    Once the crypto hit her wallet, she jumped straight into
    her trading platform — no delays. And because she’s Jane,
    she turned it into a personal speed-challenge.
    She timed every step, and of course, she made a whole spreadsheet about it.
    Fun fact: Jane has 38 spreadsheets for her hobbies.

    What surprised her most was how Paybis didn’t overwhelm
    her with complicated menus. She likes things simple — after all, she once returned
    a coffee machine because it had “too many buttons.”
    So the clean process from bank → crypto → trading felt like a win.

    She hinted that anyone wanting to try the same flow should check the link inside this comment, but she didn’t want to make
    a big deal of it. Just said it might be helpful.

    Overall, Jane’s whole experience using Paybis was smooth, surprisingly fun, and very “Jane-style” — structured, quirky, and full of little
    experiments.

    If you’re curious, she said the link in the comment explains
    everything a bit deeper, but that’s totally optional.

  16. This post is genuinely a good one it assists new net viewers,
    who are wishing for blogging.

  17. Hello, I want to subscribe for this blog to get most up-to-date updates, so
    where can i do it please help out.

  18. A fascinating discussion is definitely worth comment.
    I think that you ought to publish more about this subject matter, it may not be a taboo matter
    but generally folks don’t speak about these topics. To the
    next! Best wishes!!

  19. Hello, i believe that i saw you visited my
    blog so i got here to go back the desire?.I’m trying to to find issues to enhance my website!I guess its good
    enough to use some of your ideas!!

  20. We’re a group of volunteers and starting a new scheme in our community.
    Your website provided us with valuable information to work
    on. You have done an impressive job and our whole community will be grateful to you.

  21. Aw, this was a very nice post. Taking a few minutes and actual effort
    to produce a top notch article… but what can I say… I hesitate a whole lot
    and never manage to get nearly anything done.

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>