RequireJS导入文档 [英] RequireJS import documentation

查看:70
本文介绍了RequireJS导入文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WebStorm编辑器中使用.我的项目是将RequireJS与AMD配合使用.有一个代码示例:

Im using in WebStorm editor. My project is using RequireJS with AMD. There is an example of code:

dep.js

define([], function () {
var exports = {
  helloWorld: function() { 
    console.log("Hello world");
  }
};
return exports;
});

primary.js

define(['dep'], function (dep) {
var exports = {
  sayHello: function() {
      dep.helloWorld();
  }
};
return exports;
});

如何正确记录此类AMD模块的导出(主要在其他答案中对此进行介绍)和(重要!)导入,因此WebStorm可以在导入的dep上具有正确的类型提示(如本示例中的"dep"变量). /p>

How to document properly exports (this mainly described in other answers) and (important!) imports of such AMD modules, so WebStorm can have proper type hints on imported deps (like a "dep" variable in this example).

推荐答案

根据 AMD howto ,应该像

/**
 * @module dep
 */
define([], function() {
    /**
     * @constructor
     * @alias module:dep
     */
    var exports = {
        helloWorld: function() {
            console.log("Hello world");
        }
    };
    return exports;
});

这篇关于RequireJS导入文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆