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.

7,574 thoughts on “Using RequireJS exports with CoffeeScript

  1. I’m impressed, I have to admit. Seldom do I come across a blog that’s equally educative and engaging, and let me tell you,
    you’ve hit the nail on the head. The issue is an issue
    that not enough people are speaking intelligently about.
    I’m very happy I came across this in my hunt for something concerning this.

  2. When someone writes an piece of writing he/she maintains the plan of a user in his/her brain that how a
    user can know it. Therefore that’s why this paragraph is perfect.
    Thanks!

  3. 확실히 당신이 언급한 것을 생각합니다.
    당신의 가장 좋아하는 정당화는 웹에서 가장 단순한 요소로 기억해야 할 것처럼 보였습니다.
    저는 당신에게 말합니다, 저는 다른 사람들이 그들이 분명히 모르는 걱정를 생각할 때 짜증이 나 확실히 느낍니다.
    당신은 부작용 없이 전체을 깔끔하게 정의하고, 최고을 정확히 맞췄습니다.
    다른 사람들이 신호를 받을 수 있습니다.
    아마 더 얻기 위해 다시 올 것입니다.

    감사합니다

    Wow, superb blog layout! How long have you been running a
    blog for? you made blogging look easy. The total glance of your site is fantastic,
    let alone the content!

  4. Hi there, after reading this remarkable piece of writing i am as well cheerful to share my experience here
    with friends.

  5. Everyone loves what you guys are usually up too.
    This sort of clever work and exposure! Keep up the good works guys I’ve you guys
    to blogroll.

  6. What i don’t understood is actually how you’re not really much more smartly-favored than you might be now.
    You’re very intelligent. You know therefore significantly in the
    case of this matter, made me in my view imagine it from numerous varied
    angles. Its like women and men aren’t involved except it is one
    thing to do with Girl gaga! Your personal stuffs nice. At all times take care
    of it up!

  7. Hmm is anyone else encountering problems with the images on this
    blog loading? I’m trying to figure out if its a problem on my
    end or if it’s the blog. Any responses would be greatly
    appreciated.

  8. I’ll never forget this, but the day I stepped into the backend of the sports world, everything I thought
    I knew about modern sports completely collapsed.

    I always believed teams were about winning games, but when I saw how the entire
    industry had turned into this multi-layered financial machine, I honestly
    felt overwhelmed.

    What hit me hardest was realizing that cybercriminals weren’t going
    after “IT servers” anymore. They were attacking everything —
    medical reports. One breach, and millions could be
    lost instantly.

    And the scariest part?
    I saw it with my own eyes.

    One day, during a routine check, someone mentioned how a data leak nearly destroyed a negotiation.
    That was the moment I understood how thin the line really is between order and total
    digital disaster.

    But the real shock came when I looked deeper into betting platforms.

    I swear, I always thought they were just websites.
    But no.
    They are high-precision financial machines. One tiny manipulation can shift odds globally or make entire markets react like they’re on fire.

    When I learned how seriously regulated environments handle security — especially the kind you see described in official breakdowns — it opened my eyes.
    If anyone wants to understand how this level of protection actually works,
    they can always look it up directly from the source.
    The full explanations are there, and they’re honestly worth reading.

    Inside the clubs, it was even more surreal. I saw databases full
    of biometric performance metrics — things that could ruin a season if
    leaked.

    And yet the biggest weakness wasn’t the firewalls.

    It was the people.
    One emotional click, one careless moment, and the whole system can fall apart.
    I watched entire staff units go through security training because phishing had become a daily threat.

    Compliance teams were everywhere too — checking access, reviewing logs,
    forcing documentation. I used to think compliance was boring, but now I
    understand that without it, the entire digital side of sports would melt into chaos.

    And the future… that’s another story.

    AI detection, automated response systems, cloud architectures
    — it felt like watching the digital version of an arms race.
    But the truth I walked away with was simple:

    Cybersecurity isn’t some extra cost. It’s the only thing holding this whole world
    together.

    And honestly, after everything I saw, I can say the system I
    was reviewing really did an exceptional job. They handled their mission far better than I expected.

    If anyone wants to dig deeper or understand how these structures really work, I’d definitely suggest
    getting more information directly from the source.

    It’s all publicly explained — and believe me, once
    you read it, you’ll never look at sports or betting the same way again.

  9. Wow, that’s what I was searching for, what a material!
    present here at this weblog, thanks admin of this website.

  10. If some one desires expert view about blogging
    after that i advise him/her to pay a quick visit this web site, Keep up the pleasant work.

  11. I know this if off topic but I’m looking into starting my own blog and
    was wondering what all is needed to get set up?
    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 recommendations or advice would be greatly appreciated.
    Thanks

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>