【发布时间】:2011-03-11 10:20:23
【问题描述】:
编辑:从技术上讲,这是一个两部分的问题。我选择了涵盖一般问题的最佳答案,并链接到处理特定问题的答案。
用 jsdoc 记录匿名对象和函数的最佳方法是什么?
/**
* @class {Page} Page Class specification
*/
var Page = function() {
/**
* Get a page from the server
* @param {PageRequest} pageRequest Info on the page you want to request
* @param {function} callback Function executed when page is retrieved
*/
this.getPage = function(pageRequest, callback) {
};
};
代码中不存在PageRequest 对象或callback。它们将在运行时提供给getPage()。但我希望能够定义对象和函数是什么。
我可以创建 PageRequest 对象来记录:
/**
* @namespace {PageRequest} Object specification
* @property {String} pageId ID of the page you want.
* @property {String} pageName Name of the page you want.
*/
var PageRequest = {
pageId : null,
pageName : null
};
这很好(尽管我愿意接受更好的方法来做到这一点)。
记录callback 函数的最佳方法是什么?我想在文档中说明一下,比如回调函数的形式是:
callback: function({PageResponse} pageResponse, {PageRequestStatus} pageRequestStatus)
任何想法如何做到这一点?
【问题讨论】:
标签: javascript documentation tags jsdoc