autodoc 是毒品; https://www.npmjs.org/package/autodoc | https://github.com/dtao/autodoc
Autodoc 让您可以在 JavaScript 函数上方的 cmets 中编写测试,然后从命令行运行这些测试并自动生成文档,并在浏览器中嵌入和执行相同的测试。
想想文学编程,看看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: []
这就是源代码的样子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: []
*/
它扩展了 JSDoc https://developers.google.com/closure/compiler/docs/js-for-compiler,因此您还可以让 Google 的闭包编译器为您验证和优化很多东西。