JSDoc 3 Document Constructor / Class Parameter

How can I document the constructor (function) passed as a parameter?

Example:

/** @class */ function A() {} /** * @param {Function} aConstructor */ function createA(aClass) { return new aClass(); } 

As you can see, I can indicate that this is a function. However, I cannot specify which object this function will create. Is there any way to document this?

Thanks.

+6
source share
2 answers

As discussed in the comments, I submitted a request because it does not seem to me that I support this feature. Using the instanceof approach, "Function" is the closest to the representation of the object instance for the constructor. As already mentioned, @constructs or @returns can help you specify the output, but not the input parameter.

0
source

Google closes it with {function (new: type)} as a type declaration. I suggested that you can use something like this (I use it with AMD):

  /** @param {function(new:ClassOrInterfaceName)} aClass */ 

You can find more information here: http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#JavaScript_Types

Hope my answer can help someone)

+9
source

Source: https://habr.com/ru/post/947386/


All Articles