生成 Javascript 文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5841490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generating Javascript documentation
提问by Fran Verona
I'm looking for a way to generate documentation automatically from my Javascript project. Anyone know how can I do this?
我正在寻找一种从我的 Javascript 项目自动生成文档的方法。有谁知道我该怎么做?
As far as I know, there're some tools like JSDocbut I want to know your opinion, your best choice and why.
据我所知,有一些像JSDoc这样的工具,但我想知道您的意见、您的最佳选择以及原因。
Thanks!
谢谢!
EDIT: just to be clear, I need something like JavaDOC or PHPDocumentor but to use with my Javascript source code.
编辑:为了清楚起见,我需要像 JavaDOC 或 PHPDocumentor 这样的东西,但要与我的 Javascript 源代码一起使用。
采纳答案by Fran Verona
I found a great tutorial to create JS documentation using JSDoc. I hope it helps to someone who need it.
我找到了一个很棒的教程来使用 JSDoc 创建 JS 文档。我希望它对需要它的人有所帮助。
Create useful relevant Javascript documentation with JSDoc
使用 JSDoc 创建有用的相关 Javascript 文档
This was exactly what I need. Thanks for your answers stackers.
这正是我所需要的。感谢您的回答堆垛机。
回答by Raynos
There are tools like Natural Docsto do this. I've personally used it in the past and this works fine with javascript.
有像Natural Docs这样的工具可以做到这一点。我过去曾亲自使用过它,这在 javascript 中运行良好。
There are also tools like doccoto document source code.
还有像docco这样的工具来记录源代码。
In general auto generated documentation tends to be too restrictive and sometimes handmade API's like the jQuery API are easier to use.
一般来说,自动生成的文档往往过于严格,有时像 jQuery API 这样的手工 API 更容易使用。
Also documentation for dynamic languages is different from documentation on static languages. As API's are used differently and state exist in a more loose sense.
动态语言的文档也不同于静态语言的文档。由于 API 的使用方式不同,状态的存在更宽松。
回答by Bakunin95
If you work with node.js, i created a module that generate class diagram for javascript/node/html/css. Its based on the "WAE" extension of UML. Its called wavi. For javascript, function,variable and use of other modules are automatically recognized. You can use it for documenting your application.
如果您使用 node.js,我创建了一个为 javascript/node/html/css 生成类图的模块。它基于UML的“WAE”扩展。它叫做 wavi。对于javascript,自动识别函数、变量和其他模块的使用。您可以使用它来记录您的应用程序。
https://www.npmjs.org/package/wavi
https://www.npmjs.org/package/wavi
回答by user2272864
SmartComments+ YUIDocs
SmartComments+ YUIDocs
Using that extraordinary couple you can document a large JavaScript project in less than one minute.
使用这对非凡的夫妇,您可以在不到一分钟的时间内记录一个大型 JavaScript 项目。
SmartComments, it's a tool that allow you to create implicit comments from JavaScript source code.
SmartComments,它是一个允许您从 JavaScript 源代码创建隐式注释的工具。
You can use in the console or through of a Sublime Text Plugin.
您可以在控制台中使用或通过 Sublime Text 插件使用。
Please go to http://smartcomments.github.iofor further information.
请访问http://smartcomments.github.io了解更多信息。
回答by wires
autodoc
is teh dope; https://www.npmjs.org/package/autodoc| https://github.com/dtao/autodoc
autodoc
是毒品吗?https://www.npmjs.org/package/autodoc| https://github.com/dtao/autodoc
Autodoc lets you write tests in comments just above your JavaScript functions, then run those tests from the command line and auto-generate documentation with the same tests embedded and executing right in the browser.
Autodoc 允许您在 JavaScript 函数上方的注释中编写测试,然后从命令行运行这些测试并自动生成文档,并在浏览器中嵌入和执行相同的测试。
Think literate programming, look at http://danieltao.com/lazy.js/docs/for a nice example. Those green checkmarks are the tests.
想想文学编程,看看http://danieltao.com/lazy.js/docs/一个很好的例子。那些绿色的复选标记是测试。
? Lazy([1, 2, 4]) // instanceof Lazy.ArrayLikeSequence
? Lazy({ foo: "bar" }) // instanceof Lazy.ObjectLikeSequence
? Lazy("hello, world!") // instanceof Lazy.StringLikeSequence
? Lazy() // sequence: []
? Lazy(null) // sequence: []
This is what the source looks like github.com/../lazy.js#L86
这是源代码的样子github.com/../lazy.js#L86
/**
* Wraps an object and returns a {@link Sequence}. For `null` or `undefined`,
* simply returns an empty sequence (see {@link Lazy.strict} for a stricter
* implementation).
*
* - For **arrays**, Lazy will create a sequence comprising the elements in
* the array (an {@link ArrayLikeSequence}).
* - For **objects**, Lazy will create a sequence of key/value pairs
* (an {@link ObjectLikeSequence}).
* - For **strings**, Lazy will create a sequence of characters (a
* {@link StringLikeSequence}).
*
* @public
* @param {Array|Object|string} source An array, object, or string to wrap.
* @returns {Sequence} The wrapped lazy object.
*
*
* @examples
* Lazy([1, 2, 4]) // instanceof Lazy.ArrayLikeSequence
* Lazy({ foo: "bar" }) // instanceof Lazy.ObjectLikeSequence
* Lazy("hello, world!") // instanceof Lazy.StringLikeSequence
* Lazy() // sequence: []
* Lazy(null) // sequence: []
*/
It extends JSDoc https://developers.google.com/closure/compiler/docs/js-for-compiler, so in addition you can have Google's closure compiler verifying and optimising lot of things for you.
它扩展了 JSDoc https://developers.google.com/closure/compiler/docs/js-for-compiler,所以此外你可以让谷歌的闭包编译器为你验证和优化很多东西。
回答by Fabian Vogelsteller
回答by Jad
Which framework are you using ? (if any). I think the tool you'll choose depends a lot on that, since ideally it would have to understand class extensions and all. Otherwise I think jsDoc is a great place to start.
您使用的是哪个框架?(如果有的话)。我认为您将选择的工具在很大程度上取决于这一点,因为理想情况下它必须了解类扩展和所有内容。否则我认为 jsDoc 是一个很好的起点。