JavaScript 注释以 /*!

发布于 2024-09-04 20:42:58 字数 188 浏览 4 评论 0 原文

当评论以 / 开头时,我的编辑器 (Geany) 会更改评论的颜色*!/* ... *//* 有什么区别! ... */

My editor (Geany) changes the colour of a comment when a comment starts with /*!. What's the difference between /* ... */ and /*! ... */?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

演多会厌 2024-09-11 20:42:58

这 !防止 YUI 压缩器在压缩时删除注释。 (它只是删除 1 ! 相反。多个 ! 意味着您可以多次压缩而不会丢失注释。)它只是一个扩展,而不是 javascript 本身的一部分。

文档位于此处。搜索“C 风格注释”。

另外,我不知道有任何其他压缩器尊重!。 打包程序闭包编译器shrinksafejsmin 至少不尊重它。

The ! prevents YUI compressor from removing the comment when it compresses. (It just removes 1 ! instead. Multiple !'s mean you can compress multiple times without loss of the comment.) It's just an extension, but not part of javascript itself.

Documentation is here. Search for 'C-style comments'.

also, I'm not aware of any other compressors that respect the !. Packer, closure compiler, shrinksafe, and jsmin do not respect it at least.

情未る 2024-09-11 20:42:58

它们在 JavaScript 中都被视为注释。对于第二个,由于感叹号在里面,JavaScript 并不关心注释里面有什么。

最小化或压缩 JavaScript 文件的工具会删除 /* ... */ 内的任何内容,但会完整保留第二种注释风格。原因是有一种方法可以将版权信息保留在缩小或压缩版本的 JavaScript 文件中。

They are both treated as comments in JavaScript. For the second one, since the exclamation is inside, JavaScript doesn't care what's inside the comment anyway.

Tools that minimizes or compresses JavaScript files would get rid of anything inside /* ... */, but would leave the second style of comment intact. The reason is so that there's a way to keep the copyright information in the minified or compressed version of JavaScript files.

吝吻 2024-09-11 20:42:58

Javascript 中,没有,它们都只是内联注释。大概 geany 正在为某些文档工具或类似工具进行特殊着色(编辑:显然它是 YUI 压缩机,请参阅 x1a4答案)专门处理 /*! 注释(类似于 JSDoc< /a> 特别对待 /** 注释)。

In Javascript, there is none, they're both just inline comments. Presumably geany is doing special coloring for some documentation tool or similar (edit: apparently it's YUI Compressor, see x1a4's answer) that treats /*! comments specially (similar to the way JSDoc treats /** comments specially).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文