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

returning a function #242

Closed szepeviktor closed 10 years ago

szepeviktor commented 10 years ago

(sorry for the amount of issues by me)

Could you tell me why typeof afunc gives undefined?

<script type="text/javascript">
var curl = {
    "baseUrl": "http:\/\/www.atlantischild.hu\/a",
};
</script>
<script type='text/javascript' src='curl.js'></script>
<script type="text/javascript">
    curl(['domReady!', 'retafunc'], function (afunc) {
        console.log(typeof afunc);
    });
</script>

retafunc.js:

define(function () {

var myModule = function () {
    console.log('executing...');
}

return myModule;

});
szepeviktor commented 10 years ago

If you want to begin loading after the DOM is ready, you have to specify a "dummy" argument

curl(['domReady!', 'retafunc'], function (domready, retafunc) {
    console.log(typeof retafunc);
    retafunc();
});

or use next()

curl(['domReady!']).next(['retafunc'], function (retafunc) {
    console.log(typeof retafunc);
    retafunc();

(am I right?)

scothis commented 10 years ago

Because afunc is from the domReady! plugin instead of retafunc.

Try:

curl(['retafunc', 'domReady!'], function (afunc) {
    console.log(typeof afunc);
});

In the future, you're better off asking questions on the mailing list rather than opening issues.

szepeviktor commented 10 years ago

Thank you!