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.

17,793 thoughts on “Using RequireJS exports with CoffeeScript

  1. bayar bayar bayar bayar bayar bayarbayar bayar bayar bayar bayar bayarbayar
    bayar bayar bayar bayar bayar bayar bayar bayar bayar bayar bayarbayar bayar
    bayar bayar bayar bayarbayar bayar bayar bayar bayar bayar bayar bayar bayar bayar bayar bayarbayar bayar bayar bayar bayar bayarbayar bayar bayar bayar bayar bayar bayar bayar bayar bayar bayar bayarbayar bayar bayar bayar bayar
    bayar

  2. Fascinating blog! Is your theme custom made or did you download it
    from somewhere? A design like yours with a few simple tweeks would really make my blog jump
    out. Please let me know where you got your theme. With thanks

  3. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that
    automatically tweet my newest twitter updates. I’ve been looking for a
    plug-in like this for quite some time and was hoping maybe
    you would have some experience with something like this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to
    your new updates.

  4. Great blog you have here but I was wondering if you knew of
    any message boards that cover the same topics talked about here?
    I’d really like to be a part of community where I can get feedback from other experienced people that
    share the same interest. If you have any suggestions, please let me know.
    Thanks a lot!

  5. Deporte Ecuador funciona como un espacio informativo dedicada al análisis del ecosistema digital del deporte
    ecuatoriano. El sitio reúne contenidos que examinan el desarrollo del
    deporte ecuatoriano en el contexto de la tecnología, los datos y
    los nuevos hábitos de consumo.
    A diferencia de los portales tradicionales, no se enfoca únicamente en noticias o resultados.
    Su enfoque está en interpretar cómo opera el ecosistema deportivo actual: el
    modo en que los usuarios usan las plataformas, qué variables afectan sus decisiones y cómo evolucionan los estándares de calidad
    online.
    La información dentro del portal se organiza alrededor de varios ejes clave.

    En primer lugar, se evalúan las plataformas deportivas desde la perspectiva de la experiencia del usuario, su solidez y continuidad.
    Por otra parte, se examinan tendencias del mercado, procesos de transformación digital
    y la evolución de los hábitos de consumo deportivo en el país.

    Además, el portal también cubre cuestiones regulatorias, la seguridad digital y la toma de decisiones dentro
    del entorno online. Gracias a ello, se obtiene una perspectiva más integral del
    ámbito deportivo, combinando análisis técnico, contexto local y comportamiento del
    usuario.
    La meta principal es ofrecer información clara, organizada y de valor para comprender cómo funciona
    el deporte en la era digital. No busca dar respuestas simples,
    sino aportar claridad a un panorama digital cada vez más difícil de entender.

    La plataforma se enfoca en usuarios que quieren comprender el
    deporte más allá de lo básico: considerando su dimensión tecnológica hasta su impacto en la experiencia
    diaria.
    Dentro del texto se menciona que hay un enlace para leer el artículo completo.

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>