javascript注释

As with HTML & CSS, it is good practice to comment your code: not only for yourself, but also for anyone who might come after you. Comments also have other uses in development, which I’ll explain at the end of this article.

与HTML和CSS一样 ,注释代码是一个好习惯:不仅对您自己,而且对任何可能追随您的人也是如此。 注释在开发中还有其他用途,我将在本文结尾处进行解释。

单行JavaScript注释 (Single-Line JavaScript Comments)

Any text or code on a single line can be turned into a comment by preceding it with two forward slashes:

一行上的任何文本或代码都可以在其前面加上两个正斜杠来变成注释:

// this is a single-line comment

While this works well for brief descriptions or to comment out one line of non-functional code, it doesn’t provide the space needed for longer explanations. In addition, there is a small risk that a long single-line comment will accidentally catch an errant carriage return and accidentally break over two lines. If that happens, the second uncommented line will cause a syntax error.

尽管这对于简短的描述或注释掉一行非功能性代码非常有效,但它并没有提供较长的解释所需的空间。 此外,单行较长的注释可能会误捕获错误的回车符并意外中断两行。 如果发生这种情况,第二条未注释的行将导致语法错误。

多行JavaScript注释 (Multi-Line JavaScript Comments)

Multi-line comments in JavaScript are exactly the same as those in CSS:

JavaScript中的多行注释与CSS中的注释完全相同:

/* this is a
multi-line comment */

Multi-line comments are obviously much more flexible than the single line version.

多行注释显然比单行版本更灵活。

在开发中使用注释 (Using Comments In Development)

Comments are not only useful for leaving notes and reminders, but for temporarily removing problematic code from execution:

注释不仅对留下注释和提醒有用,而且对于从执行中临时删除有问题的代码也非常有用:

function pill(dose) {
bottle++;
// gulp++; this commented line will not be executed
}

This can be very useful, but of course you must be careful in only commenting out code that you don’t want to run.

这是非常有用的,当然你必须只注释掉的代码,你希望运行小心。

IE奇数:条件编译 (IE Oddities: Conditional Compilation)

Like HTML conditional comments, Internet Explorer version 10 and below (and only IE) will run code in JavaScript comments if the comment starts with a /*@cc_on @*/ statement. This can be used to target earlier versions of IE with JavaScript without affecting other browsers. More information on conditional compilation can be found at the Microsoft Internet Explorer Dev Center.

与HTML条件注释一样,如果注释以/*@cc_on @*/开头,则Internet Explorer 10及更低版本( IE)将在JavaScript注释中运行代码。 这可以用于使用JavaScript定位IE的早期版本,而不会影响其他浏览器。 有关条件编译的更多信息,请访问Microsoft Internet Explorer开发中心 。

删除生产注释 (Removing Comments For Production)

It’s a good and common practice to strip comments, whitespace and any unused code from scripts before deploying them on a live site, to minimize file size and load time. Tools such as Uglify.js can do this automatically in a build process; alternatively, an online JS minifier can be employed. Of course, it’s vital to preserve the original fully formatted and commented code for future work.

在脚本中删除注释,空格和任何未使用的代码,然后再将它们部署到实时站点上是一个好习惯,这是最小化文件大小和加载时间的最佳做法。 诸如Uglify.js之类的工具可以在构建过程中自动执行此操作。 或者,可以使用在线JS缩小器。 当然,保留原始的完整格式和注释代码对于以后的工作至关重要。

“如果我想在精简的JS代码中保留一些注释怎么办?” (“What If I Want To Preserve Some Comments In Minified JS Code?”)

In certain cases you might want to preserve some comments in your scripts, such as those containing copyright claims, developer credits and licensing information, while removing all others. Many minifiers will preserve JS comments if they contain one of two character strings:

在某些情况下,您可能希望在脚本中保留一些注释,例如包含版权声明,开发人员信用和许可信息的注释,同时删除所有其他注释。 如果许多压缩器包含两个字符串之一,它们将保留JS注释:

string meaning
@preserve general preservation rule for comments
@license a comment that contains licensing information
含义
@preserve 通用注释保存规则
@license 包含许可信息的评论

So a comment that included the following:

因此,一条评论包括以下内容:

/* @preserve
A shoutout to all my West Side homies. Nerds4Lyfe.
*/

Would be retained as a comment (sans the @preserve keyword) in the minified, production version of the JavaScript code.

将在JavaScript代码的@preserve生产版本中保留为注释( @preserve关键字)。

翻译自: https://thenewcode.com/932/JavaScript-Comments

javascript注释

javascript注释_JavaScript注释相关推荐

  1. 注释嵌套注释_DIY注释

    注释嵌套注释 从Java 5开始,Java中出现了注释. 我想做一个自己的注释,只是为了看看需要什么. 但是,我发现它们只是接口. 有擦 接口后面没有牙. 必须执行一些代码. 我认为这是橡胶行之有效的 ...

  2. java处理注释_Java注释处理器

    java处理注释 本文是我们名为" 高级Java "的学院课程的一部分. 本课程旨在帮助您最有效地使用Java. 它讨论了高级主题,包括对象创建,并发,序列化,反射等. 它将指导您 ...

  3. 注释嵌套注释_注释,无处不在的注释

    注释嵌套注释 十年前的2004年 , Java 1.5开始提供注释. 很难想象没有此功能的代码. 实际上,首先引入了注释,以减轻开发人员编写繁琐的样板代码的痛苦,并使代码更具可读性. 考虑一下J2EE ...

  4. 注释嵌套注释_注释梦Night

    注释嵌套注释 @XmlElementWrapper(name="orders") @XmlJavaTypeAdapter(OrderJaxbAdapter.class) @XmlE ...

  5. java接口废弃注释_Java注释Override、Deprecated、SuppressWarnings详解

    四.如何对注释进行注释 这一节的题目读起来虽然有些绕口,但它所蕴涵的知识却对设计更强大的java程序有很大帮助. 在上一节讨论了自定义注释,由此我们可知注释在J2SE5.0中也和类.接口一样.是程序中 ...

  6. python 注释含注释_Python注释

    python 注释含注释 Python注释 (Python comments) Comments in Python are used to improve the readability of th ...

  7. jpa 表注释和字段注释_JPA注释–Hibernate注释

    jpa 表注释和字段注释 JPA annotations are used in mapping java objects to the database tables, columns etc. H ...

  8. 三菱PLC伺服XZ轴定位程序 程序都有注释、注释全面,用的三菱FX3U系列plc

    三菱PLC伺服XZ轴定位程序 程序都有注释.注释全面,用的三菱FX3U系列plc,本程序为X轴Z轴伺服定位控制程序,可借鉴.可做模板,本程序已经设备实际批量应用.稳定生产.成熟可靠,自己辛苦编写的程序 ...

  9. Oracle读取数据库中表填充,Oracle数据库中查看所有表和字段以及表注释.字段注释...

    1.获取表: select table_name from user_tables; //当前用户拥有的表 select table_name from all_tables; //所有用户的表 se ...

最新文章

  1. 使用Xcode和Instruments调试解决iOS内存泄露(转)
  2. CircleDisplay
  3. 个人博客代码_这四个博客模板美观大气,做个漂亮的个人博客必须得收藏
  4. mq 接口 java_Rabbitmq Java Client Api详解
  5. 7、Docker容器数据卷volumes-from
  6. AIoT五营连开惊喜活动上线!
  7. AppSettings和ConnectionStrings的区别
  8. 查看 linux 硬件信息:内存、分区、系统、环境变量、防火墙、路由、端口监听、进程、CPU...
  9. [转载] Java面试题大全(2020版)
  10. Android Learning:数据存储方案归纳与总结
  11. 视觉SLAM笔记(8) 齐次坐标
  12. UGUI之Toggle使用
  13. 卷组删除pv_CentOS下删除一个卷组(VG)
  14. Beini FeedingBottle[小巧的无线密码破解系统]
  15. 还在找一款编辑友好,美观方便的开源wiki系统?安利一款超好用wiki
  16. 2017年5月—信息安全工程师—上午综合知识(11-15)
  17. JAVA之父,詹姆斯·高斯林传奇人生
  18. openssl rand
  19. QT MPlayer播放器
  20. 写一个搜索引擎系统(Java版)

热门文章

  1. 计算机的桌面过大要怎么改,win7桌面图标太大了如何设置变小?
  2. SQL注入攻击原理及防护方案
  3. shell 编程三剑客之一:grep 详解
  4. Tomcat 能稳定支持的最大用户并发数(详解)
  5. dhl:类型“System.Data.Objects.DataClasses.EntityObject”在未被引用的程序集中定义必须添加对程序集“System.Data.Entity引用...
  6. 库存管理:批量入库怎么做?手机端也可以做
  7. TypeScript方法重载
  8. Oracle Database 11g安装时显示[INS-13001]环境不满足最低要求。
  9. W5500EVB实现NetBIOS协议
  10. 三分钟带你了解元宇宙和快来新宇宙