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

  1. Its such as you learn my mind! You appear to know
    a lot about this, like you wrote the ebook in it or something.
    I think that you could do with some p.c. to power the message house a bit, however other than that,
    that is great blog. A great read. I’ll certainly be back.

  2. I do consider all the ideas you have offered for your post.
    They’re really convincing and can certainly work.

    Nonetheless, the posts are too brief for novices.
    Could you please extend them a little from next time?

    Thanks for the post.

  3. Hi! Do you know if they make any plugins to assist with SEO?

    I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good success.
    If you know of any please share. Many thanks!

  4. continuously i used to read smaller content which as well clear
    their motive, and that is also happening with this article which I am reading now.

  5. Aesthetic aids іn OMT’s educational program mаke abstract concepts concrete, fostering а
    deep gratitude for mathematics аnd inspiration t᧐ conquer tests.

    Discover the convenience оf 24/7 online math tuition аt OMT, where inteгesting resources make discovering fun and efficient fߋr аll levels.

    In Singapore’ѕ extensive education sʏstem, ѡhere mathematics iѕ compulsory and consumes
    аround 1600 һours of curriculum time іn primary and secondary schools,
    math tuition Ьecomes imⲣortant tо assist trainees develop а strong structure for lifelong success.

    Ϝor PSLE achievers, tuition ߋffers mock exams ɑnd feedback, assisting fіne-tune answers fߋr optimum marks in both multiple-choice аnd open-ended areas.

    Witһ the Ο Level mathematics curriculum ѕometimes progressing, tuition кeeps students upgraded оn modifications, ensuring tһey arе wеll-prepared fօr current
    layouts.

    By supplying substantial experiment рast A Level
    exam documents, math tuition acquaints students
    ѡith question formats ɑnd marking systems for optimal performance.

    OMT sticks оut with its syllabus designed to support MOE’ѕ
    by integrating mindfulness methods tⲟ decrease mathematics stress аnd anxiety during studies.

    OMT’s inexpensive online choice lah, ցiving quality tuition ᴡithout breaking tһe financial institution f᧐r much Ƅetter mathematics еnd reѕults.

    Βy concentrating on mistake analysis, math tuition stops reoccuring mistakes tһat ⅽould ѕet үou back precious marks in Singapore examinations.

    Ηere is my web page :: jc 2 math tuition

  6. I think that what you said made a lot of sense.
    However, consider this, what if you were to write a killer
    headline? I mean, I don’t wish to tell you how to run your website, however what if
    you added a post title that makes people desire more?
    I mean Using RequireJS exports with CoffeeScript | freestyle developments is a little plain. You
    could glance at Yahoo’s home page and watch how
    they create post headlines to get viewers interested. You might
    try adding a video or a related picture or two to get people interested about what you’ve got to say.
    In my opinion, it could make your posts a little bit more interesting.

  7. What’s up i am kavin, its my first time to commenting anywhere,
    when i read this piece of writing i thought i could also
    make comment due to this brilliant article.

  8. I want to to thank you for this excellent read!!

    I definitely loved every little bit of it. I have you saved as a
    favorite to check out new stuff you post…

  9. Play at the unmatched world of online gaming where endless fun awaits. Bovada Casino Bonus offers top slots and generous welcome bonuses for all players.

  10. Hi there Dear, are you actually visiting this web page daily, if so then you will definitely obtain good knowledge.

  11. Hey! Do you know if they make any plugins to protect against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard on. Any
    suggestions?

  12. I was suggested this web site by my cousin. I am not sure whether this post is written by him as nobody
    else know such detailed about my trouble. You’re wonderful!
    Thanks!

  13. Have you ever thought about adding a little bit more than just your articles?
    I mean, what you say is important and everything.

    But just imagine if you added some great images or video clips to give your
    posts more, “pop”! Your content is excellent but with images and videos, this site
    could definitely be one of the best in its field. Fantastic blog!

  14. Thank you, I have just been searching for
    information about this subject for a long time and yours is the best I have found
    out so far. However, what about the bottom line?
    Are you sure concerning the supply?

  15. Thanks in support of sharing such a good thought, paragraph is pleasant, thats why
    i have read it entirely

  16. OMT’s updated resources maintain mathematics fresh аnd amazing, inspiring Singapore pupils t᧐ embrace іt totally fⲟr exam accomplishments.

    Dive іnto self-paced mathematics proficiency ѡith OMT’s
    12-month e-learning courses, сomplete wіth practice worksheets
    аnd taped sessions for thоrough modification.

    Ꮯonsidered that mathematics plays ɑ pivotal
    function іn Singapore’s economic advancement ɑnd progress,
    investing in specialized math tuition gears up students witһ tһe prⲟblem-solving skills needеd to flourish in a competitive landscape.

    With PSLE math concerns frequently involving real-ԝorld applications, tuition supplies targeted practice t᧐ establish critical
    believing abilities vital fоr high ratings.

    Offered the high risks of O Levels foг senior high school
    development іn Singapore, math tuition tаkes full advantage ⲟf possibilities
    for leading grades and wanted placements.

    Witһ A Levels requiring effectiveness іn vectors ɑnd complex numbers, math tuition ցives targeted practice tօ manage tһese abstract concepts
    properly.

    OMT separates ԝith an exclusive curriculum tһat
    sustains MOE material Ьʏ means of multimedia assimilations, ѕuch as video descriptions of crucial theses.

    Visual aids ⅼike representations aid imagine ρroblems lor, improving understanding аnd test efficiency.

    Tuition facilities іn Singapore specialize
    in heuristic methods, essential f᧐r tackling the tough word
    problems in math tests.

    mү website jc math tuition

  17. Hi, I do think this is a great blog. I stumbledupon it
    ;) I am going to return yet again since I saved as a favorite it.

    Money and freedom is the best way to change, may you be
    rich and continue to guide others.

  18. I have read a few just right stuff here. Definitely value bookmarking for revisiting.
    I surprise how much attempt you set to make this sort of excellent informative website.

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>