简体   繁体   English

英镑符号(#)评论从JavaScript开始?

[英]Pound Sign (#) As Comment Start In JavaScript?

Does the pound sign (#) start a comment in JavaScript? 英镑符号(#)是否在JavaScript中发表评论? I have a website I am using with NPM and when I tried to minify the JavaScript with Grunt, Uglify threw the error: 我有一个我正在使用NPM的网站,当我尝试用Grunt缩小JavaScript时,Uglify抛出错误:

Warning: Uglification failed.
Unexpected character '#'.
Line 1 in app/min-libs/node_modules/grunt-contrib-jshint/node_modules/jshint/nod
e_modules/cli/examples/cat.js
 Use --force to continue.

The file name being referred to seems to be from another NPM module, meaning they know what they are doing. 被引用的文件名似乎来自另一个NPM模块,这意味着他们知道自己在做什么。 So when I went to app/min-libs/node_modules/grunt-contrib-jshint/node_modules/jshint/node_modules/cli/examples/cat.js, the offending line says: 所以当我去app / min-libs / node_modules / grunt-contrib-jshint / node_modules / jshint / node_modules / cli / examples / cat.js时,违规行说:

#!/usr/bin/env node

Is this a comment or do the owners of this NPM module know some super-secret forbidden JavaScript technique? 这是一个评论还是这个NPM模块的所有者知道一些超级秘密的禁止JavaScript技术?

It is not a JavaScript technique, but a *nix OS one. 它不是JavaScript技术,而是* nix OS。 It is called shebang . 它叫做shebang Quoting from Wiki 引自维基

Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script's initial line as an interpreter directive; 在类Unix操作系统下,当一个带有shebang的脚本作为程序运行时,程序加载器会将脚本初始行的其余部分解析为解释器指令; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the scrip 而是运行指定的解释器程序,将其作为参数传递给尝试运行脚本时最初使用的路径

So, the cat.js file can be executed in the shell, like an executable (if it has executable permission). 因此, cat.js文件可以在shell中执行,就像可执行文件一样(如果它具有可执行权限)。

cat.js

instead of 代替

node cat.js

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

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