英镑符号(#)作为注释从JavaScript开始吗? [英] Pound Sign (#) As Comment Start In JavaScript?

查看:76
本文介绍了英镑符号(#)作为注释从JavaScript开始吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

井号(#)是否在JavaScript中开始注释?我有一个正在与NPM一起使用的网站,当我尝试使用Grunt缩小JavaScript大小时,Uglify抛出了错误:

Does the pound sign (#) start a comment in JavaScript? I have a website I am using with NPM and when I tried to minify the JavaScript with Grunt, Uglify threw the error:

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.

被引用的文件名似乎来自另一个NPM模块,这意味着他们知道自己在做什么.因此,当我转到app/min-libs/node_modules/grunt-contrib-jshint/node_modules/jshint/node_modules/cli/examples/cat.js时,令人反感的一行说:

The file name being referred to seems to be from another NPM module, meaning they know what they are doing. 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:

#!/usr/bin/env node

这是评论吗,还是此NPM模块的所有者知道某些超级秘密的禁止JavaScript技术?

Is this a comment or do the owners of this NPM module know some super-secret forbidden JavaScript technique?

推荐答案

这不是JavaScript技术,而是* nix OS技术.它称为 shebang .从Wiki报价

It is not a JavaScript technique, but a *nix OS one. It is called shebang. Quoting from Wiki

在类似Unix的操作系统下,运行带有shebang的脚本时作为程序,程序加载器解析脚本的其余部分初始行作为解释器指令;指定的口译员而是运行程序,将原本的路径作为参数传递给它最初在尝试运行脚本时使用

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; 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

因此, cat.js 文件可以在shell中执行,就像可执行文件一样(如果具有可执行文件的权限).

So, the cat.js file can be executed in the shell, like an executable (if it has executable permission).

cat.js

代替

node cat.js

这篇关于英镑符号(#)作为注释从JavaScript开始吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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