最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript jsdoc namespace class static method - Stack Overflow

programmeradmin0浏览0评论

I'm trying to use jsDoc on my js code in which I want to define: - A Namespace. - A Class. - A Static Method. Note that the code does exactly what I expect at runtime, but I have problems to getting started with jsDoc, so I question myself if code is correct...

/** @namespace
 * @name myNamespace
 * @description myNamespace description.
 */
if (typeof (myNamespace) == "undefined") myNamespace = { };

/** @class 
 * @name myClass
 * @description myClass description.
 * @memberof myNamespace
 * @inner
 */
myNamespace.myClass = function () { };

/** @method
 * @name myStaticMethod
 * @description myStaticMethod description.
 * @param {String} myParam. Required. myParam description.
 * @return myReturnValue description.
 * @remarks remarks description.
 * @memberof myNamespace.myClass
 * @inner
 */
myNamespace.myClass.myStaticMethod = function (myParam) {
    var myReturnValue = myParam;
    return myReturnValue;
};

When I generate with jsDoc I see in the index: - Correct myNamespace definition. - Correct myClass definition. When I go inside myClass I cannot see myStaticMethod... myStaticMethod is not present anywhere. My JS is coded correctly? If is correctly coded... Is the ments correctly written? What's wrong?

Thanks a lot...

I'm trying to use jsDoc on my js code in which I want to define: - A Namespace. - A Class. - A Static Method. Note that the code does exactly what I expect at runtime, but I have problems to getting started with jsDoc, so I question myself if code is correct...

/** @namespace
 * @name myNamespace
 * @description myNamespace description.
 */
if (typeof (myNamespace) == "undefined") myNamespace = { };

/** @class 
 * @name myClass
 * @description myClass description.
 * @memberof myNamespace
 * @inner
 */
myNamespace.myClass = function () { };

/** @method
 * @name myStaticMethod
 * @description myStaticMethod description.
 * @param {String} myParam. Required. myParam description.
 * @return myReturnValue description.
 * @remarks remarks description.
 * @memberof myNamespace.myClass
 * @inner
 */
myNamespace.myClass.myStaticMethod = function (myParam) {
    var myReturnValue = myParam;
    return myReturnValue;
};

When I generate with jsDoc I see in the index: - Correct myNamespace definition. - Correct myClass definition. When I go inside myClass I cannot see myStaticMethod... myStaticMethod is not present anywhere. My JS is coded correctly? If is correctly coded... Is the ments correctly written? What's wrong?

Thanks a lot...

Share asked Sep 19, 2014 at 8:51 FalcoFalco 1,6063 gold badges21 silver badges53 bronze badges 3
  • Side note: typeof is an operator, not a function; there's no need for parens around the value, for the same reason you can just write 1 + 2 rather than (1) + (2) and new ClassName() rather than new (ClassName()). – T.J. Crowder Commented Sep 19, 2014 at 9:00
  • Separately, your code relies on The Horror of Implicit Globals to create myNamespace. The better way is: var myNamespace; (which has no effect at all if it already exists) followed by your typeof test. – T.J. Crowder Commented Sep 19, 2014 at 9:01
  • Thanks I'll take in mind and will try to refactor the code... – Falco Commented Sep 19, 2014 at 9:10
Add a ment  | 

2 Answers 2

Reset to default 3

If you're going to use @name, you need to tell JsDoc what the member is; using @name tells JsDoc to pletely ignore context.

In your case, I think you need to add @static (you already have @memberof, so that's good).

T.J. Crowder was right, I cannot vote becouse I'm young in munity, this is the corrected code ments for jsDoc if someone need:

/** @namespace
 * @name myNamespace
 * @description myNamespace description.
 */
if (typeof (myNamespace) == "undefined") myNamespace = { };

/** @class 
 * @name myNamespace.myClass
 * @description myClass description.
 * @memberof myNamespace
 * @inner
 */
myNamespace.myClass = function () { };

/** @function
 * @static
 * @name myNamespace.myClass.myStaticMethod
 * @description myStaticMethod description.
 * @param {String} myParam. Required. myParam description.
 * @return myReturnValue description.
 * @remarks remarks description.
 * @memberof myNamespace.myClass
 * @inner
 */

myNamespace.myClass.myStaticMethod = function (myParam) {
    var myReturnValue = myParam;
    return myReturnValue;
};
发布评论

评论列表(0)

  1. 暂无评论