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,930 thoughts on “Using RequireJS exports with CoffeeScript

  1. Howdy! I know this is kind of off-topic however
    I had to ask. Does running a well-established blog like yours take a lot of work?
    I’m brand new to operating a blog however I do write in my journal everyday.
    I’d like to start a blog so I can easily share my experience and feelings
    online. Please let me know if you have any kind of recommendations or tips for brand
    new aspiring blog owners. Appreciate it!

  2. It’s the best time to make some plans for the future and it is
    time to be happy. I’ve read this post and if I could I desire to suggest you some interesting things or suggestions.
    Maybe you can write next articles referring to this article.
    I desire to read even more things about it!

  3. Great blog! Do you have any recommendations for aspiring writers?
    I’m hoping to start my own blog soon but I’m a
    little lost on everything. Would you advise starting with a free platform like WordPress
    or go for a paid option? There are so many choices out there that I’m totally confused ..
    Any tips? Kudos!

  4. Magnificent web site. Lots of helpful information here. I am sending it to several
    friends ans also sharing in delicious. And of course, thanks for your sweat!

  5. Ahaa, its fastidious dialogue on the topic of this article here at this website, I have read all that, so at this time me also commenting here.

  6. I need to to thank you for this excellent read!!

    I definitely enjoyed every bit of it. I’ve got you saved as a
    favorite to look at new things you post…

  7. Hi there! I could have sworn I’ve visited this web site before but after going through many of the articles I realized it’s
    new to me. Regardless, I’m certainly happy I discovered it and I’ll
    be book-marking it and checking back regularly!

  8. Here’s a quick share of how Jane ended up using Paybis to shift her money from her bank
    into crypto and then straight into her trading account, and honestly, her whole
    story turned out way more entertaining than anyone thought.

    Jane isn’t your regular crypto newbie. Fun fact: 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: quick setup, easy deposit,
    and she was able to convert her bank funds into crypto in literally
    minutes. She laughed saying it was easier than ordering sushi.

    Once the crypto hit her wallet, she jumped straight into her trading platform — zero friction. And because she’s Jane,
    she turned it into a personal speed-challenge.
    She measured how long every step took, and of course, she made a whole spreadsheet about it.
    Little detail: she names her spreadsheets after planets.

    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.

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

    For anyone interested, she said the link in the comment
    explains everything a bit deeper, but that’s totally optional.

  9. Thanks for the good writeup. It in truth used to be a enjoyment account it.
    Glance advanced to more delivered agreeable from you!

    By the way, how could we communicate?

  10. Hey There. I found your blog using msn. That is a really neatly written article.
    I’ll be sure to bookmark it and come back to learn more of your helpful info.
    Thank you for the post. I will certainly comeback.

  11. I don’t know if it’s just me or if perhaps everybody else experiencing
    issues with your site. It looks like some of the
    text on your content are running off the screen. Can somebody else please
    comment and let me know if this is happening
    to them too? This could be a issue with my web browser because
    I’ve had this happen previously. Many thanks

  12. Услуга по увеличению показателей в Дзене: подписчики, дочитки и лайки для роста активности и видимости канала. Переходите по запросу раскрутка яндекс дзен. Поможем быстро усилить социальные сигналы, повысить привлекательность публикаций и ускорить продвижение. Подходит для новых и действующих каналов, чтобы улучшить статистику и привлечь больше реальной аудитории.

  13. I constantly spent my half an hour to read this web site’s articles or reviews every day along with a mug of coffee.

  14. Hi88 không đơn thuần là một nền tảng cá cược trực tuyến, mà còn là điểm đến giải
    trí hiện đại được thiết kế phù
    hợp với người chơi Việt Nam. Sở hữu phương thức vận hành chuyên nghiệp, giao diện tối ưu
    theo nhu cầu người dùng cùng kho trò
    chơi được tuyển chọn từ các nhà cung cấp uy tín hàng đầu châu Á, Hi88 mang đến trải nghiệm
    cá cược ổn định, an toàn và đầy cuốn hút.

  15. I have read so many content on the topic of the blogger lovers however this piece
    of writing is genuinely a pleasant article, keep it up.

  16. I’m really impressed with your writing skills as well as with the
    layout on your blog. Is this a paid theme or did you modify it yourself?
    Either way keep up the nice quality writing, it is rare
    to see a great blog like this one nowadays.

  17. I enjoy what you guys are usually up too. This sort of clever work and exposure!
    Keep up the good works guys I’ve added you guys to my own blogroll.

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>