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

  1. Нужна бесплатная юридическая консультация? Переходите по запросу консультация юриста бесплатно онлайн без номера телефона в Омской области и получите помощь опытного юриста по любым правовым вопросам: семейные споры, долги, недвижимость, трудовые конфликты, защита прав потребителей и многое другое. Задайте вопрос онлайн или по телефону и получите подробный разбор вашей ситуации и рекомендации по дальнейшим действиям. Консультация проводится бесплатно и конфиденциально.

  2. I recently came across an detailed article about this crypto
    service Paybis and honestly it stood out to me.

    The post broke down how beginners can get into crypto safely, and
    it wasn’t full of complicated jargon.
    After going through it, I recommended it to my family
    member, and he started learning more about crypto. Within the next
    month, he looked at new income opportunities.

    He didn’t just sit around — he actually applied what he learned.

    Eventually, he even pushed towards 200k depending on timing —
    not overnight, but through consistency.
    What surprised me most is how his lifestyle
    changed. He even treated himself to a new car, something like a
    BMW 3 Series, and started enjoying life more. He even found
    a partner who enjoys the same level of comfort.

    This isn’t magic or guaranteed, but the story is genuine, and that article definitely changed the way we look at money.

    There’s actually a reference mentioned here, and
    I’d seriously suggest reading it.
    Opportunities are everywhere if you look closely.

  3. In this instance, the life insurance company’s cash.

    Stop by my web site – lawsuit info justin baldoni website (Everett)

  4. Wow that was strange. I just wrote an incredibly long comment but after I clicked submit my comment didn’t show up.
    Grrrr… well I’m not writing all that over again. Regardless, just wanted
    to say excellent blog!

  5. netent casino list usa, legitimate online casino in canada and whats the largest casino in australia, or casinos in victoria bc united kingdom

    My website – vera och john free spins (Adrienne)

  6. This is a helpful post about gambling websites.
    I appreciate how you explained the importance of choosing
    reliable sites.

    From what I’ve seen, UFABET888 are often recommended because they offer stable performance and secure transactions.

    Many bettors often struggle to find trustworthy platforms, so content like this is extremely useful.

    Thanks for sharing — this will definitely help both beginners and experienced players make smarter decisions.

  7. Additionally, the blackjack game featured an intelligent AI-powered dealer that reacted to
    player decisions in a realistic and immersive way.

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>