jsdoc

How to properly define own type of class in JSDoc?

烈酒焚心 提交于 2020-01-14 16:31:18
问题 I have a simple ES6 class and I'm wondering how to properly describe it in JSDoc. Note that I want to define my own type, which later would be recognized by WebStorm autocomplete. Is below example valid? /** * @typedef {Object} View * @class */ class View{...} 回答1: That's a really good question. The way I do today is to declare all my class instance variables in its constructor, annotating each one with its expected type. It's a good practice and works very well with Webstorm. For instance:

Documenting the return of a javascript constructor with jsdoc

[亡魂溺海] 提交于 2020-01-14 12:52:35
问题 I have a javascript function that returns a constructor (see code sample below). How would I document this with the @returns tag of jsdoc. It doesnt seem correct to do @returns {MyConstructor} because that implies I am returning an instance of "MyConstructor" rather than the constructor itself, right? function MyConstructor() { var self = this; self.myFunction = function() { return true; }; self.getMyFunctionResult = function() { return self.myFunction(); }; } /** * @returns {?} A constructor

How to use JSDoc3 to document nested namespaces

梦想的初衷 提交于 2020-01-14 07:35:07
问题 I'm having trouble using JSDoc3 to document code that's structured along these lines /** * @namespace MyNamespace.MySubNamespace */ (function (MyNamespace) { MyNamespace.MySubNamespace.Foo = { doSomething: function (someParam) { // doing it } } })(window.MyNamespace) How would I use JSDoc3 to document that MyNamespace contains MySubNamespace which contains Foo ? Further how would I associate doSomething with Foo and document its parameter someParam ? A limitation I have is that I can't add

Comment nested module class with JSDoc3

断了今生、忘了曾经 提交于 2020-01-14 03:06:29
问题 I'm dealing with a module pattern in WebStorm's live inspection that I'm trying to comment. And I don't want to use AMD/CJS. ; My = (window.My || {}); My.Module = (My.Module || {}); My.Module.MyClass = (/** * * @param {My.Module.MyAnotherClass} MyAnotherClass */ function (MyAnotherClass) { 'use strict'; /** * @class */ var MyClass = function() { // constructor }; /** * My sexy method. * @param {string} s */ MyClass.prototype.myMethod= function(s) { var test = new MyAnotherClass(s); }; return

Documenting factories with JSDoc

怎甘沉沦 提交于 2020-01-13 08:30:32
问题 In order to avoid using new in my JavaScript code, I write factories to create objects. I have tried many combinations and the one that gives me the most satisfactory result is the following: /** * Document module * @module app/document */ (function () { 'use strict'; /** * Factory that creates a document object. * @alias module:app/document.factory * @return {document} */ function document() { /** * Get document id * @method id * @return {String} */ var id = function id() {...}, api = { id:

How to describe “object” arguments in jsdoc?

。_饼干妹妹 提交于 2020-01-08 18:16:09
问题 // My function does X and Y. // @params {object} parameters An object containing the parameters // @params {function} callback The callback function function(parameters, callback) { } But how do I describe how the parameters object should be structured? For example it should be something like: { setting1 : 123, // (required, integer) setting2 : 'asdf' // (optional, string) } 回答1: From the @param wiki page: Parameters With Properties If a parameter is expected to have a particular property,

How do I jsdoc parameters to web request?

落爺英雄遲暮 提交于 2020-01-06 05:45:06
问题 I have functions like this (in Node.js/Firebase) and wonder how to add documentation i JSDoc format: exports.getUserRes = functions.https.onRequest(async (request, response) => {...} How do I document the GET/POST/etc parameters to the request ? 回答1: I just found an old question with an answer that seems to suggest a good way. It is not the accepted answer there I mean, but the answer by @Steven Spunkin: javascript - How to annotate Express middlewares with JSDoc? - Stack Overflow How to

How to make WebStorm resolve modules which are functions?

时间秒杀一切 提交于 2020-01-01 08:49:48
问题 WebStorm does a very good job of resolving functions which are returned from CommonJS modules as methods (and reads JsDoc associated with them), like for instance: // utils/valid.js /** * Returns true no matter what. * @param {HTMLElement} element * @return {boolean} */ function isValid(element) { return true; } module.exports.isValid = isValid; // exports property Such a function is then correctly provided in code completion and inline documentation mechanisms when such a module is required

How to make WebStorm resolve modules which are functions?

半城伤御伤魂 提交于 2020-01-01 08:49:10
问题 WebStorm does a very good job of resolving functions which are returned from CommonJS modules as methods (and reads JsDoc associated with them), like for instance: // utils/valid.js /** * Returns true no matter what. * @param {HTMLElement} element * @return {boolean} */ function isValid(element) { return true; } module.exports.isValid = isValid; // exports property Such a function is then correctly provided in code completion and inline documentation mechanisms when such a module is required

How to “import” a typedef from one file to another in JSDoc using Node.js?

纵然是瞬间 提交于 2020-01-01 02:10:38
问题 Let's say I have a file named "File1.js". In this file, I export an object of objects and I give each object a typedef, like so. /** * My typedef for each object. * @typedef {Object} MyObject1 * @property {String} username Your username * @property {String} realname Your real name. * @property {boolean} isUnique Are you unique as a person? */ module.exports = { /** * Person One! * @type {MyObject1} */ myperson: { username: 'TheDragonSlayer', realname: 'George', isUnique: true }, /** * Person