How do I document a member function from a father class. There is a class A with a member function Afunc(), and I am gonna document class B extends A.
I do not overwrite Afunc() in B, yet I need the function Afunc() appear in my document, how do I do it?
I wrote
/**
* description
* #function Afunc
* #memberOf A
*/
It works that appears Afunc in the document, yet there is a <static> tag at the start of the function name.
How do I solve it?
Thanks everyone.
jsdoc 3.2.2 does what you want by default. In this example, the method B.foo will automatically be documented because B extends A and does not override foo:
/**
* #class
*/
function A() {
}
/**
* Foo the flerbl.
* #param {Object} flerbl The flerbl.
*/
A.prototype.foo = function (flerbl) {
};
/**
* #class
* #extends A
*/
function B() {
}
B.prototype = new A();
Otherwise, you must use # in your #memberof tag to mark the object as an belonging to an instance of the class:
/**
* description
* #function Afunc
* #memberof A#
*/
Related
I'm using the documentation package, but cannot figure out how to get it to document class properties (that aren't defined via getters and setters).
As the following just generates class documentation for SomeClass, but omits the someProperty documentation.
/**
* SomeClass is an example class for my question.
* #class
* #constructor
* #public
*/
class SomeClass {
constructor () {
this.someProperty = true // how do I document this?
}
/**
* someProperty is an example property that is set to `true`
* #property {boolean} someProperty
* #public
*/
}
An aside: the #constructor on the class jsdoc is a documentation thing.
Move the JSDoc for someProperty into the constructor where it is first defined:
/**
* SomeClass is an example class for my question.
* #class
* #constructor
* #public
*/
class SomeClass {
constructor () {
/**
* someProperty is an example property that is set to `true`
* #type {boolean}
* #public
*/
this.someProperty = true
}
}
I'm unsure if there is a way of accomplishing it with the documentation package using an approach that doesn't involve inlining the JSDocs into the constructor.
Another way is to declare them in class documentation as follows:
/**
* Class definition
* #property {type} propName - propriety description
* ...
*/
class ClassName {
constructor () {...}
...
}
You can declare properties in a class, and use #type to declare a type for them. Worked in VSCode 1.70.2 with in a plain ECMAScript Module.
class Foo {
/**
* Some bary data
* #type { BarClass }
*/
bar;
}
let f = new Foo();
f.bar; // Intellisense can tell you type and purpose
I need some wrapper classes for converting values from XML to javascript and back. The setup looks like this:
/**
* #template T
* */
class Value {
/**
*
* #param {Element} valueNode
*/
constructor(valueNode) {
this.node = valueNode;
}
/** #type {T} **/
get value() {
return this.node.hasAttribute("value") ? this.convertToJS(this.node.getAttribute("value")) : null;
}
/**
* Must be overriden and provide JS object/variable from the string value
* #param {string} stringValue
* #returns {T}
*/
convertToJS(stringValue) { }
}
/**
* #class
* #extends Value<boolean>
* */
class BoolValue extends Value {
/**
* Must be overriden and provide JS object/variable from the string value
* #param {string} stringValue
* #returns {T}
*/
convertToJS(stringValue) { return stringValue == "true"; }
}
When I have an instance if BoolValue, I'd like visual studio to know that myVar.value is a boolean.
How to tell JSDoc that a class extends a templated class with specific type?
I probably did not understand the question, but
When I have an instance if BoolValue, I'd like visual studio to know that myVar.value is a boolean.
works fine with your current setup :D
I have this class
/**
* #constructor
* #param {...*} var_args
*/
var Map = function(var_args) {
// insert all pairs of parameters as objects in the map
};
/**
* #constructor
* #extends {Map}
* #param {...*} var_args
*/
var ExtendedMap = function(var_args) {
goog.base(this, var_args); //<-- this obviously doesn't work!
};
goog.inherits(ExtendedMap, Map);
The problem araises given that ExtendedMap needs to extend a class (Map) which in it's constructor already has a var_args. How do I add my own constructor without messing up with the parent's constructor? I'm using the google-closure compiler.
You don't need to use goog.base, it is just a method to make things easier. In this case you would call the Map's constructor directly and using apply instead of call:
/**
* #constructor
* #extends {Map}
* #param {...*} var_args
*/
var ExtendedMap = function(var_args) {
Map.apply(this, arguments);
};
goog.inherits(ExtendedMap, Map);
I'm writing documentation with yuidoc. However, I have a class Model, which has one of its methods defined elsewhere. Here is some code to visualize the situation.
Assume I have a file model.js:
/**
* #class Model
* #constructor
*/
window.Model = function(){}
....
And a file activerecord.js:
(function(){
/**
* #class ActiveRecord
* #constructor
window.ActiveRecord = function(){}
....
/**
* #method Model.hasMany
* #param {Class} model
*/
function hasMany(model) {}
})() ;
As you can see, the method 'hasMany' should show up under the class documentation of Model. However, it doesn't. Is something like this possible ?
Thanks a lot
See the #for tag: http://yui.github.io/yuidoc/syntax/index.html#for
/**
* Some method "hasMany" disconnected from its class "Model".
*
* #method hasMany
* #for Model
* #param {Class} model
*/
function hasMany(model) {}
So I have several object definitions that work like this:
(function () {
var parent= constructors.Parent.prototype;
/**
* Creates an instance of Child.
*
* #constructor
* #augments Parent
* #this {Child}
* #param {object} settings
*/
var Child= function(settings) {
constructors.Parent.apply(this, arguments); //calling parent constructor
//constructor code
}
Child.prototype= new constructors.Parent();
/**
* Method1
*
* #this {Child}
* #param {string} param1
* #param {number} param2
*/
Child.prototype.method1= function(param1, param2) {
parent.method1.apply(this,arguments); //calls "super"
//method code
}
constructors.Child= Child;
}());
I do all this so that only global variable is 'constructors' and so that I don't have to say 'construtors.Child' all the time. But JSDoc3 is ignoring my comments and generates nothing on this code. Anyone knows any special tags to fix this? I don't mind if the JSDoc shows my class name as 'Child' or 'constructors.Child', either way is fine.
use #public in front of #class/#module/#namespace
see https://github.com/jsdoc3/jsdoc/issues/442
I'm not sure if this is the right way to do it, but it worked:
On another file I now have the following:
/**
* #module constructors
*/
constructors= {}
And in the file mentioned before I now have:
/**
* #exports constructors
*/
(function () {
var parent= constructors.Parent.prototype;
/**
* Creates an instance of Child.
*
* #constructor
* #augments Parent
* #this {Child}
* #param {object} settings
*/
var Child= function(settings) {
constructors.Parent.apply(this, arguments); //calling parent constructor
//constructor code
}
Child.prototype= new constructors.Parent();
/**
* Method1
*
* #this {Child}
* #param {string} param1
* #param {number} param2
*/
Child.prototype.method1= function(param1, param2) {
parent.method1.apply(this,arguments); //calls "super"
//method code
}
constructors.Child= Child;
}());