开发者

How to document this using jsdoc? [closed]

Closed. This question is opinion-based. It is not currently acce开发者_开发百科pting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 5 years ago.

Improve this question

I'd like to know how to document this type of class using jsdoc:

var MyObject = (function(){

  var that = {};

  function privateFunction(){};

  that.publicFunction = function(){};

  that.publicField = "foo";

  return that;

})();


There are a number of things named JSDoc, but using closure compiler annotations which work with jsdoc toolkit, you can use @constructor to mark MyClass as a constructor.

/** @constructor */
var MyClass = ...;

Then you can make it clear that that is of the nominal type MyClass though obviously that nominal type won't work with instanceof.

/** @type MyClass */
var that = /** @type {MyClass} */ {};

The first @type establishes the type of the declaration, and the second is a type assertion/cast for the value.

With the methods you can use the @this annotation.

/** @this MyClass */
that.publicFunction = function () { ... };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜