1

I'm currently working with requirejs. I'm trying to define a specific, existing object as a module, but I can't get it to work.

Actually, I'm using an example from their website: http://requirejs.org/docs/whyamd.html#namedmodules

> define('myModule', [], function () {
>    return function () {};
> });
undefined

> requirejs('myModule')
undefined

> requirejs.defined('myModule')
false

In this shell, both requirejs and define exist, and are coming from requirejs.

Am I doing something wrong?

1 Answer 1

1

You can only? fetch the module using the specified callback in require:

define('myModule', [], function () {
   return function () {};
});
requirejs(['myModule'], function(myModule) {
  console.log(myModule);
});
Sign up to request clarification or add additional context in comments.

2 Comments

When I do that, console.log(myModule) prints the requirejs function. However, once that step is done, myModule can be loaded via a var myModule = requirejs('myModule');. That sounds weird, is there something to know about it?
This works cause, once loaded the callback is not necessary anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.