Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous Module Definition: difference between beta.verb() and require("beta").verb()

I was studying Asynchronous Module Definition from wiki.commonjs.org and I am wondering what is the meaning of this piece of code.
In particular, my question is:
return beta.verb(); and return require("beta").verb(); have the same effect.
If not what is the difference?

define("alpha", ["require", "exports", "beta"], function (require, exports, beta) {
    exports.verb = function() {
        return beta.verb();
        //Or:
        return require("beta").verb();
    }
});
like image 839
Lorraine Bernard Avatar asked Dec 27 '25 16:12

Lorraine Bernard


1 Answers

beta is already initialized to the value of require("beta") before the callback function is called. From the definition of define on that page:

The dependencies [argument] must be resolved prior to execution of the module factory function, and the resolved values should be passed as arguments to the factory function with argument positions corresponding to index in the dependencies array

like image 171
Eric Avatar answered Dec 30 '25 06:12

Eric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!