Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the preferred method of commenting javascript objects & methods [closed]

I'm used to Atlas where the preferred (from what I know) method is to use XML comments such as:

/// <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) { ... } 

Recently I've been looking into other third-party JavaScript libraries and I see syntax like:

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

As a bonus, are there API generators for JavaScript that could read the 'preferred' commenting style?

like image 582
EvilSyn Avatar asked Sep 24 '08 13:09

EvilSyn


People also ask

How do you comment a method in JavaScript?

In JavaScript, single-line comments begin with // . It will ignore all the things immediately after // syntax until the end of that line. This is also known as inline commenting when we use // syntax alongside codes lines.

What is the right kind of JavaScript comment?

Single-line comments are generally used to comment a part of the line or full line of code. Single-line comments in JavaScript start with // . The interpreter will ignore everything to the right of this control sequence until the end of the line.

Which of the following is used to comment in JavaScript?

JavaScript comments are used to write notes in your code or to disable sections of code without deleting them. Comments are made in JavaScript by adding // before a single line, or /* before and */ after multiple lines.


2 Answers

There's 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; } 
like image 71
Chris MacDonald Avatar answered Sep 22 '22 08:09

Chris MacDonald


The simpler the better, comments are good, use them :)

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() {     // ... } 

But for autogenerated doc...

/**  * 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() {     // ... } 
like image 30
molokoloco Avatar answered Sep 22 '22 08:09

molokoloco