RequireJS import documentation

China☆狼群 提交于 2019-12-10 23:14:24

问题


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;
});

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).


回答1:


According to AMD howto, it should be smth like

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


来源:https://stackoverflow.com/questions/21232208/requirejs-import-documentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!