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

  1. Почему пользователи выбирают
    площадку KRAKEN?
    Маркетплейс KRAKEN заслужил доверие многочисленной аудитории благодаря сочетанию ключевых факторов.
    Во-первых, это широкий и разнообразный ассортимент, представленный сотнями продавцов.
    Во-вторых, интуитивно понятный интерфейс KRAKEN,
    который упрощает навигацию, поиск товаров и управление заказами
    даже для новых пользователей. В-третьих, продуманная
    система безопасных транзакций,
    включающая механизмы разрешения
    споров (диспутов) и возможность использования условного депонирования, что минимизирует риски для обеих сторон сделки.
    На KRAKEN функциональность сочетается с внимательным отношением к
    безопасности клиентов, что делает процесс покупок более предсказуемым, защищенным и, как следствие, популярным среди пользователей, ценящих анонимность и надежность.

  2. Калибровочные гири M1 для весов нужного класса точности и номинальной массы для калибровки весов.
    В нашей компании можно купить гири M1 эталонные массой от 1 кг до 2000 кг.
    Предлагаем гири класса M1 для торговых, складских, производственных и технических весов.

  3. در کل داستان

    برای اونایی که می‌خوان وارد بشن

    سایت‌های شرطی

    درگیر هستن

    اینجا

    کاملا میتونه

    ارزش امتحان داشته باشه

    نکته جالب اینه که

    نام‌هایی مثل

    enfeјaronline حرفه‌ای

    و

    sibbet جدید

    اثرگذار بودن

    در پایان کار

    تجربه مثبتی داشتم

    و

    احتمالا

    استفاده خواهم کرد

    My web site … تجربه بازی انفجار در یک محیط امن و سریع

  4. This is a fantastic article regarding the current home
    renovation trends in the region. Selecting the right Interior design Malaysia partner is
    undoubtedly a top priority for new homeowners today. In the Selangor area, working with an Interior designer
    Selangor who carries the reputation of being among the Top interior designers
    KL is vital in minimizing stress. I’ve noticed that the Design and build interior design Malaysia model
    offered by Jolivin Interiors provides a highly efficient solution,
    particularly when it comes to precision-engineered Custom kitchen cabinet Malaysia work.
    For those residing in the suburbs, Interior design Puchong is seeing massive growth, and the range
    of Interior design services Klang Valley is more impressive than ever.

    Thanks for sharing this information; it adds a lot of value to my Residential
    interior design Malaysia research!

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>