admin管理员组文章数量:1305158
How can I document a 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 specify that it is a function. However, I can't specify which object that function would create. Is there some way to document this?
Thanks.
How can I document a 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 specify that it is a function. However, I can't specify which object that function would create. Is there some way to document this?
Thanks.
Share Improve this question asked Jun 16, 2013 at 1:59 samanimesamanime 26.6k17 gold badges97 silver badges150 bronze badges 5-
Why not under
@returns
like@returns {A}
or if multiple types are possible, you could do@returns {A|B}}
? – Brett Zamir Commented Jun 16, 2013 at 2:20 -
It appears you may be able to do this with
@constructs <name>
(see the 2nd example at usejsdoc/tags-constructs.html ) – Brett Zamir Commented Jun 16, 2013 at 2:29 - In this exact case, I would indeed return that data type. However, that doesn't strictly denote that it is the expected data type of the parameter itself. Same with your other example. – samanime Commented Jun 16, 2013 at 3:15
- I'd file a request because it doesn't appear to me to support that capability. Using the approach of instanceof, "Function" is the closest for the time being... – Brett Zamir Commented Jun 16, 2013 at 7:42
- After hunting, I think you are correct. If you want to post that as answer, I'll accept it. – samanime Commented Jun 16, 2013 at 8:46
2 Answers
Reset to default 9Google with its closure propose a {function(new:type)} as a type description. I've assumed, that one can use something like this (I'm using it with AMD):
/** @param {function(new:ClassOrInterfaceName)} aClass */
You can find more information here: http://google-styleguide.googlecode./svn/trunk/javascriptguide.xml#JavaScript_Types
I hope, my answer can help someone )
As discussed in the ments, I'd file a request because it doesn't appear to me to support that capability. Using the approach of instanceof, "Function" is the closest in representing the object instance for a constructor for the time being. As mentioned, @constructs or @returns
may be able to help you to indicate the output, but not the parameter input.
本文标签: javascriptJSDoc 3 Document constructorclass parameterStack Overflow
版权声明:本文标题:javascript - JSDoc 3 Document constructorclass parameter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741783307a2397436.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论