RequireJS import documentation

2019-07-20 13:32发布

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条回答
我想做一个坏孩纸
2楼-- · 2019-07-20 13:39

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;
});
查看更多
登录 后发表回答