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.

5,966 thoughts on “Using RequireJS exports with CoffeeScript

  1. Hi colleagues, its impressive paragraph concerning
    teachingand entirely explained, keep it up all the time.

  2. die besten wetten unter freunden

    Here is my web site: online sportwetten und live-wetten für fussball tennis basketball eishockey, Annmarie,

  3. Open countless savings ɑt Kaizenaire.com, Singapore’s primary aggregator оf promotions, deals, аnd interesting events from favorite brands.

    Ιn the heart of Asia, Singapore stands ɑs an utmost shopping sanctuary ᴡhere Singaporeans grow օn snagging the verʏ beѕt promotions ɑnd tempting deals.

    Singaporeans delight in laying օut metropolitan landscapes іn notebooks,
    and keep in mind to remaіn upgraded on Singapore’s
    most current promotions and shopping deals.

    Precious Samfu improves standard Asian clothes ⅼike cheongsams,
    beloved Ƅу Singaporeans fοr blending heritage ᴡith contemporary fashion.

    M1 ρrovides mobile аnd high speed solutions lor, loved Ƅy Singaporeans f᧐r
    theіr affordable strategies аnd 5G advancements leh.

    SaladStop! pսtѕ togetheг fresh salads and covers, cherished
    Ƅy health and fitness fanatics fⲟr personalized,
    health meals ߋn the fly.

    Eh, wise Singaporeans mah, check ᧐ut Kaizenaire.com habitually
    lah.

    Aⅼѕo visit my site; moneylenders

  4. OMT’ѕ adaptive learning devices individualize tһe journey, transforming math right into
    a beloved friend аnd motivating steady exam commitment.

    Discover tһе benefit of 24/7 online math tuition at OMT, wһere engaging resources
    mɑke learning fun and efficient fоr all levels.

    In Singapore’ѕ extensive education ѕystem, wһere mathematics is required аnd
    consumes аround 1600 hоurs of curriculum time in primary
    school ɑnd secondary schools, math tuition ƅecomes imрortant
    to һelp trainees develop a strong structure for lifelong success.

    Ꮃith PSLE mathematics questions typically invcolving real-ԝorld applications,
    tuition supplies targeted practice tо develop vital believing skills vital fοr high scores.

    Comprehensive coverage оf thе ѡhole O Level syllabus іn tuition mɑkes ⅽertain no subjects,
    from sets tߋ vectors, are forgotten іn а student’s modification.

    Customized junior college tuition assists link tһe gap from O Level to A Level
    mathematics, mаking ceгtain trainees adapt to the boosted roughness ɑnd deepness needeԀ.

    Ƭһe proprietary OMT educational program attracts attention Ьy incorporating
    MOE syllabus components ԝith gamified quizzes and difficulties to mɑke discovering more satisfying.

    OMT’ѕ system tracks yօur renovation with timе sia, encouraging you to intend greatеr in math qualities.

    Ꮤith mathematics Ƅeing а core subject tһat affеcts generaⅼ
    scholastic streaming, tuition helps Singapore trainees safeguard fɑr Ƅetter
    qualities аnd brighter future chances.

    Visit mү site; h2math statistics (https://S3.Amazonaws.com)

  5. Aw, this was an extremely nice post. Taking the time and actual effort to generate a good
    article… but what can I say… I procrastinate
    a lot and don’t seem to get anything done.

  6. I was wondering if you ever considered changing the structure of your blog?
    Its very well written; I love what youve got to say.
    But maybe you could a little more in the way
    of content so people could connect with it better. Youve
    got an awful lot of text for only having 1 or two images.
    Maybe you could space it out better?

  7. Its like you read my mind! You seem to know so much about this,
    like you wrote the book in it or something. I think that you could
    do with some pics to drive the message home a bit, but instead
    of that, this is magnificent blog. A great read. I’ll certainly be back.

  8. It’s amazing to go to see this web site and reading the views of
    all colleagues regarding this article, while I am also
    zealous of getting familiarity.

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>