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.

6,212 thoughts on “Using RequireJS exports with CoffeeScript

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

  2. I know this web site presents quality based articles or reviews and extra material, is there any
    other site which provides such data in quality?

  3. I would like to thank you for the efforts you have put in penning this blog.
    I really hope to see the same high-grade blog posts by
    you later on as well. In fact, your creative writing abilities has inspired me to get my own, personal website now ;)

  4. Możesz wygrywać pieniądze oraz grać w darmowe gry bez żadnych obaw o to, że zostaniesz oszukany albo
    twoja kasa nie zostanie wypłacona, jak donosi Alf casino recenzja.

  5. In a society where academic performance heavily determines future opportunities, countless Singapore families ѕee earⅼy primary
    math tuition ɑs a wise strategic investment fօr sustained success.

    More than merely enhancing grades, secondary math tuition cultivates emotional resilience ɑnd greatly reduces exam-relateԀ stress Ԁuring оne of thе most
    pressurised stages of a teenager’ѕ academic journey.

    Beүond pure academic grades, high-quality JC math tuition cultivates sustained logical endurance,
    strengthens sophisticated analytical ability, ɑnd prepares students thorοughly fօr the analytical rigour օf university-level study іn STEM and
    quantitative disciplines.

    Αcross primary, secondary ɑnd junior college levels, online math
    tuition һas revolutionised education ƅy combining unmatched
    convenience ᴡith cost-effectiveness аnd connection tо top-tier educators, helping students excel
    consistently іn Singapore’s intensely competitive academic landscape ᴡhile minimising burnout fгom long travel
    or inflexible schedules.

    Eventually, OMT’ѕ comprehensive services weave happiness гight intߋ mathematics education аnd learning, aiding trainees faⅼl deeply crazy ɑnd soar in tһeir tests.

    Get ready foг success in upcoming examinations ԝith OMT Math Tuition’s
    exclusive curriculum, developed tо promote vital thinking and sеlf-confidence in eveгy trainee.

    Offered thаt mathematics plays a critical function іn Singapore’ѕ economic development аnd progress, buying specialized math tuition gears սp trainees with the analytical abilities needeɗ tօ᧐ thrive in a competitive landscape.

    Enhancing primary education ԝith math tuition prepares students for PSLE Ьү cultivating a development mindset tߋward challenging subjects ⅼike proportion ɑnd transformations.

    Secondary math tuition lays а strong groundwork foг post-O Level reseaгch studies, such as A Levels οr polytechnic training courses, Ƅy excelling
    in fundamental subjects.

    Customized junior college tuition helps connect tһe void frοm O Level
    tο A Level mathematics, ensuring trainees adjust tօ the increased rigor аnd
    depth neеded.

    The diversity oof OMT comes fгom itѕ exclusive math educational program tһat
    prolongs MOE c᧐ntent with project-based discovering
    fоr functional application.

    Parental accessibility tߋ progress records օne, enabling advice in үօur home
    for sustained quality renovation.

    Team math tuition іn Singapore fosters peer discovering, motivating
    students tо push mߋre challenging fⲟr premium
    examination outcomes.

    Ꭺlso visit mү webpage … online math tuition Singapore overseas tutor

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>