aspyct
aspyct

Reputation: 3875

requirejs - Cannot define named module

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?

Upvotes: 1

Views: 951

Answers (1)

Andreas Louv
Andreas Louv

Reputation: 47099

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

define('myModule', [], function () {
   return function () {};
});
requirejs(['myModule'], function(myModule) {
  console.log(myModule);
});

Upvotes: 1

Related Questions