JavaScript中代码注释的正确方法是什么 [英] What is the correct way of code comments in JavaScript

查看:66
本文介绍了JavaScript中代码注释的正确方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Javascript中代码注释的正确方法是什么-与Java中的语法相同吗?以及哪些工具实际上会利用这些注释:

What is the correct way of code comments in Javascript - is the same syntax as in Java? And which tools actually would take advantage of these comments:

  /*
  * Add an element to the group
  * @param {Object}  overlayElement
  * @param {Object} [element2] optional element
  */ 

我发现新的Resharper 6(我在Visual Studio 2010中写了JS)提供的注释与C#中的注释相同,但仅在函数体内,如///< param name ="overlayElement"><;/param>.ReSharper不会突出显示JS代码注释.

I found new Resharper 6 (I write JS in VisualStudio 2010) offers the same comments as in C#, but only within the functions body, something like /// <param name="overlayElement"></param> . The JS code comments are not highlighted as such by ReSharper.

最好的方法是...?

推荐答案

使用//优于/* */,因为这样您就可以使用后者删除包含其他注释的整个块.但是,如果要使用自动文档生成工具,则必须使用类似于javaDoc样式的注释.

using // is better than /* */ because then you can use the latter to take out an entire block containing other comments. However, if you want to use an automatic documentation generation tool, you must use comments similar to javaDoc style.

这是一个可以与YUI DOC(最好的)一起使用的示例. https://yui.github.io/yuidoc/

This is an example that would work with YUI DOC (best one) https://yui.github.io/yuidoc/

/**
* This is a description
* @namespace My.Namespace
* @method myMethodName
* @param {String} some string
* @param {Object} some object
* @return {bool} some bool
*/

这篇关于JavaScript中代码注释的正确方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆