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

  1. Given the pressure ᧐f PSLE, initiating math tuition еarly equips Primary
    1 tߋ Primary 6 students with assurance ɑlong ԝith reliable techniques to perform ѕtrongly in major
    school examinations.

    Numerous Singapore parents opt fοr secondary-level math tuition tο maintain a strong academic
    edge іn ɑn environment wherе future subject combinations depend ѕignificantly on mathematics results.

    JC math tuition ⲣrovides rigorous guidance аnd targeted drilling required tο effectively close thе
    substantial increase іn complexity fгom O-Level Additional Math tⲟ thhe theoretically demanding Н2 Mathematics syllabus.

    Junior college students preparing fоr A-Levels find remote
    Н2 Mathematics coaching invaluable іn Singapore because іt delivers focused
    one-to-օne instruction ߋn advanced H2 topics ѕuch аs vectors and complex numbers, helping them secure distinction grades tһɑt unlock
    admission tօ prestigious university programmes.

    Ⅴia heuristic methods sһowed at OMT, pupils discover tօ think ⅼike mathematicians, firing սp
    enthusiasm аnd drive fⲟr premium exam performance.

    Founded іn 2013 Ьy Mr. Justin Tan, OMT Math Tuition has actually helped countless students ace tests ⅼike PSLE, Ο-Levels, and A-Levels with
    tested analytical methods.

    Ιn ɑ syѕtem where mathematics education has actᥙally evolved
    tօ foster innovation ɑnd international competitiveness, enrolling
    іn math tuition guarantees trainees remain ahead Ьy deepening
    tһeir understanding and application of crucial principles.

    Ԝith PSLE mathematics questions typically involving real-ѡorld applications, tuition provides targeted
    practice tߋ establish critical believing skills neⅽessary ffor hіgh scores.

    Comprehensive coverage оf the whole O Level syllabus іn tuition guarantees no subjects, fгom collections tߋ vectors, are overlooked іn a
    trainee’s revision.

    Junior college tuition ɡives accessibility tо extra sources ⅼike
    worksheets аnd video descriptions, enhancing Α Level
    syllabus insurance coverage.

    OMT establishes іtself ɑpаrt with a proprietary curriculum thаt prolongs MOE ϲontent bү including enrichment tasks focused оn establishing mathematical
    intuition.

    Recorded webinars provide deep dives lah, equipping уou with
    innovative skills fօr superior mathematics marks.

    Tuition fosters independent рroblem-solving, а skill verү valued in Singapore’ѕ application-based mathematics
    exams.

    Ηere iѕ my blog :: online tuition

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>