简体   繁体   English

hashbang (#?) 在客户端有任何功能吗?

[英]Does the hashbang (#!) have any functionality client side?

I recently learned about the hashbang syntax for writing comments in JavaScript, and need to know if it is or has the potential to be any different then just putting a // at the top of a file.我最近了解了用于在 JavaScript 中编写注释的hashbang语法,并且需要知道它是否或有可能与将//放在文件顶部有任何不同。 Are there any conventions associated with the hashbang?是否有任何与 hashbang 相关的约定?

I am referring to usage in a browser environment only , not in a shell or NodeJS, etc.我指的是仅在浏览器环境中使用,而不是在 shell 或 NodeJS 等中使用。

I am asking because I am writing about JavaScript syntax and need to make sure it is 100% correct.我问是因为我正在写有关 JavaScript 语法的文章,需要确保它 100% 正确。

Hashbang has no meaning to JavaScript, as far as it's concerned it's just a comment. Hashbang 对 JavaScript 没有任何意义,就它而言它只是一个注释。 The only reason it exists is because Unix treats files beginning with #!它存在的唯一原因是因为 Unix 处理以#! specially when you try to run them as commands, and this can be used to run node.js automatically on a server.特别是当您尝试将它们作为命令运行时,这可用于在服务器上自动运行node.js

This is meaningless in a browser, which loads scripts explicitly.这在显式加载脚本的浏览器中毫无意义。 So The hashbang has no special function on the client.所以hashbang在客户端没有特殊功能。

No, #!不, #! doesn't have any JavaScript functionality, neither on the server nor on the client side.没有任何 JavaScript 功能,无论是在服务器端还是在客户端。 It's just a comment that does nothing.这只是一个什么都不做的评论。 It has a functionality in executable files on some operating systems, but that has nothing to do with JavaScript - it's just to allow writing JavaScrit scripts as text files that make use of this operating system functionality.它在某些操作系统上的可执行文件中具有功能,但这与 JavaScript 无关——它只是允许将 JavaScrit 脚本编写为文本文件,以利用该操作系统功能。

On a related note, JavaScript does also use<!-- … and --> as comment syntax , which is equally useless in non-HTML context like in serverside javascript, but it's permitted for compatibility anyway.在相关说明中,JavaScript 也使用<!-- …-->作为注释语法,这在非 HTML 上下文中(如在服务器端 javascript 中)同样无用,但无论如何它是允许兼容性的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM