评论javascript对象的首选方法是什么?方法

时间:2008-09-24 13:23:09

标签: javascript comments

我习惯使用atlas,首选(据我所知)方法是使用xml注释,例如:

/// <summary>
///   Method to calculate distance between two points
/// </summary>
///
/// <param name="pointA">First point</param>
/// <param name="pointB">Second point</param>
/// 
function calculatePointDistance(pointA, pointB) { ... }

最近我一直在研究其他第三方javascript库,我看到的语法如下:

/*
 * some comment here
 * another comment here
 * ...
 */
 function blahblah() { ... }

作为奖励,如果有任何可以读取“首选”评论风格的JavaScript API生成器,请告诉我。

5 个答案:

答案 0 :(得分:66)

JSDoc

/**
 * Shape is an abstract base class. It is defined simply
 * to have something to inherit from for geometric 
 * subclasses
 * @constructor
 */
function Shape(color){
 this.color = color;
}

答案 1 :(得分:11)

越简越好,评论很好,使用它们:)

var something = 10; // My comment

/*
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.
*/

function bigThing() {
    // ...
}

但对于自动生成的文档...

/**
 * Adds two numbers.
 * @param {number} num1 The first number to add.
 * @param {number} num2 The second number to add.
 * @return {number} The result of adding num1 and num2.
 */
function bigThing() {
    // ...
}

答案 2 :(得分:7)

雅虎提供YUIDoc

有很好的文档,由Yahoo支持,是一个Node.js应用程序。

它也使用了很多相同的语法,因此不需要进行很多更改就可以从一个更改为另一个。

答案 3 :(得分:2)

尝试将以下内容粘贴到Visual Studio 08中的javascript文件中并使用它:

var Namespace = {};
    Namespace.AnotherNamespace = {};

Namespace.AnotherNamespace.annoyingAlert = function(_message)
{
    /// <param name="_message">The message you want alerted two times</param>
    /// <summary>This is really annoying!!</summary>

    alert(_message);
    alert(_message);
};

Intellisense嘉豪!

有关此内容的更多信息(包括如何引用外部javascript文件,以便在大型库中使用)可以在Scott Gu's blog找到。

答案 4 :(得分:1)

在第一个示例中使用三重注释实际上用于外部XML文档工具和(在Visual Studio中)智能感知支持。它仍然是一个有效的评论,但它的特殊:)实际评论'运营商'是// 唯一的限制是它的单行。

第二个示例使用C样式块注释,允许跨多行或在行的中间进行注释。