cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

What if the module is a function? #274

Closed zengfenfei closed 9 years ago

zengfenfei commented 9 years ago
//...
define(['dep1', 'dep2', 'dep3' /* etc */], module);
define(module);
//...
define(name, ['dep1', 'dep2', 'dep3' /* etc */], module);
define(name, module);

As the doc says above, if the module is a function then the module value is the function itself or the return value of function?

unscriptable commented 9 years ago

Hello @zengfenfei,

To define a function-module, you must use a factory function (a.k.a. "definition function"):

define(['dep1', 'dep2', 'dep3' /* etc */], function (dep1, dep2, dep3) {
    // do preparation work here
    return function () {
        // this is your function-module
    };
});

If you look further down in the README.md, there are other examples of function-modules.

I'm closing this issue, but feel free to continue the conversation. :)

-- John