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.

10,252 thoughts on “Using RequireJS exports with CoffeeScript

  1. I am not sure where you’re getting your info, but great topic.
    I needs to spend some time learning more or understanding more.
    Thanks for magnificent information I was looking for this info for my mission.

  2. I’m amazed, I have to admit. Seldom do I encounter a blog that’s both equally educative and entertaining, and without a doubt,
    you have hit the nail on the head. The problem is an issue
    that too few people are speaking intelligently about.

    I’m very happy that I stumbled across this during my search
    for something concerning this.

  3. Many Singapore parents choose primary math tuition tο ensure their children ҝeep pace іn the demanding MOE syllabus
    аnd avoid falling Ƅehind compared tⲟ classmates.

    In Singapore’ѕ rigorous secondary education landscape, math tuition ƅecomes indispensable fߋr students to
    confidently conquer challenging topics including advanced algebra,
    geometry, trigonometry, ɑnd statistics that fߋrm the core foundation f᧐r О-Level achievement.

    JC math tuition delivers tһe structured support and exam-oriented repetition required tо effectively close tһe major
    conceptual leap from О-Level Additional Math tо the highly abstract Ꮋ2 Mathematics syllabus.

    Acгoss primary, secondary ɑnd junior college levels, virtual mathematics support һas revolutionised education ƅy combining
    exceptional flexibility with vaⅼue-driven instruction аnd availability of expert guidance, helping students perform ɑt theіr beѕt in Singapore’ѕ intensely
    competitive academic landscape ᴡhile minimising burnout from long travel
    or inflexible schedules.

    Project-based discovering ɑt OMT turns mathematics іnto hands-on fun, triggering intеrest in Singapore trainees for
    superior exam outcomes.

    Broaden уoսr horizons witһ OMT’s upcoming new physical аrea opening in Տeptember 2025,
    providing еven morе opportunities foг hands-on mathematics exploration.

    Singapore’ѕ focus on crucial analyzing mathematics highlights tһе ᴠalue
    оf marh tuition, ԝhich helps trainees develop
    tһe analytical skills demanded by the country’ѕ forward-thinking syllabus.

    Tuition highlights heuristic рroblem-solving ɑpproaches, imρortant f᧐r
    dealing ѡith PSLE’s tough wߋrd issues tһat
    require multiple steps.

    Ᏼy offering comprehensive exercise ѡith previous Ⲟ
    Level papers, tuition furnishes pupils ԝith
    familiarity and the capacity to prepare fⲟr question patterns.

    Junior college math tuition promotes collective understanding іn tiny teams, enhancing peer
    discussions on complex Α Level concepts.

    OMT’s proprietary syllabus complements tһe MOE curriculum by giving
    step-Ƅy-step failures of intricate topics, mаking sure pupils develop а stronger
    foundational understanding.

    OMT’ѕ system tracks yօur enhancement with time sia,encouraging уou tߋ aim
    gгeater in mathematics grades.

    Tuition programs track development diligently, encouraging Singapore pupils ԝith noticeable enhancements resulting in examination goals.

    Feel free tߋ visit my homepaɡe: A Math tuition Singapore

  4. Hey there, I think your site might be having browser compatibility issues.

    When I look at your website in Opera, it looks fine but
    when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that,
    great blog!

  5. I’m really enjoying the theme/design of your web
    site. Do you ever run into any web browser compatibility
    problems? A few of my blog audience have complained about my
    blog not working correctly in Explorer but looks great in Opera.
    Do you have any suggestions to help fix this problem?

  6. Remarkable! Its really awesome article, I have got much clear
    idea concerning from this post.

  7. Бесплатная консультация юриста по расторжению брака поможет разобраться в ваших правах и возможностях при разводе. Специалист объяснит порядок развода через суд или ЗАГС, подскажет, как решаются вопросы раздела имущества, алиментов и проживания детей. Перейдя по запросу консультация юриста по разводам бесплатно вы получите профессиональные рекомендации и ответы на все вопросы, чтобы пройти процедуру развода максимально спокойно и с защитой ваших интересов.

  8. I was recommended this web site by my cousin. I’m not sure whether this post is written by him as nobody else
    know such detailed about my difficulty. You’re amazing! Thanks!

  9. Why viewers still use to read news papers when in this technological world everything is
    accessible on web?

  10. I am no longer positive where you are getting your information, but great topic.
    I needs to spend a while finding out much more
    or understanding more. Thanks for fantastic information I used to be on the
    lookout for this information for my mission.

  11. Just want to say your article is as astonishing. The clarity in your post is
    simply cool and i can assume you’re an expert on this subject.
    Well with your permission let me to grab your RSS feed to
    keep up to date with forthcoming post. Thanks a million and please carry on the rewarding work.

  12. Hi there, just became alert to your blog through Google, and found that it is truly
    informative. I am going to watch out for brussels. I will be grateful if you continue this
    in future. A lot of people will be benefited from your writing.
    Cheers!

  13. 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 a few pics to drive the message home a little bit, but other
    than that, this is wonderful blog. An excellent read.
    I will certainly be back.

    Here is my webpage: kkpoker rakeback

  14. I’m really enjoying the design and layout of your site.
    It’s a very easy on the eyes which makes it much more enjoyable for me
    to come here and visit more often. Did you hire out a developer to create your theme?
    Fantastic work!

  15. Heya! I’m at work browsing your blog from my new iphone 3gs!

    Just wanted to say I love reading through your blog and look forward to
    all your posts! Carry on the fantastic work!

  16. I blog frequently and I truly appreciate your information. This great article has really peaked
    my interest. I am going to take a note of your website and keep checking for new information about once per week.
    I opted in for your Feed as well.

  17. I really like it whenever people come together
    and share views. Great blog, keep it up!

  18. Im gone to tell my little brother that he should also visit this blog on regular basis to get updated from most up-to-date reports. viagraonline2

  19. I’m really enjoying the theme/design of your site. Do you ever
    run into any internet browser compatibility issues? A handful of my blog audience
    have complained about my website not working correctly in Explorer but looks great in Firefox.

    Do you have any advice to help fix this problem?

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>