简体   繁体   English

requirejs-无法定义命名模块

[英]requirejs - Cannot define named module

I'm currently working with requirejs. 我目前正在使用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 实际上,我正在使用他们网站上的示例: 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. 在这个shell中,requirejs和define都存在,并且都来自requirejs。

Am I doing something wrong? 难道我做错了什么?

You can only? 你只能吗 fetch the module using the specified callback in require: 使用require中的指定回调获取模块:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM