本文介绍了JSLint报告“意外的悬空”下划线前缀变量名称中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有些人认为存在一个前导下划线意味着变量是私有的,这种隐私是虚构的,并且假设这就是为什么JSLint会使用错误消息报告此类名称。

I know that some people consider the presence of a leading underscore to imply that a variable is "private," that such privacy is a fiction, and assume this is why JSLint reports such names with an error message.

我在我正在建设的网站上使用Google Analytics。我参考GA的变量,例如_gaq。。

I use Google Analytics on a Web site I am building. I make reference to GA's variables, such as "_gaq."

我试图让我的JS代码100%JSLint干净(我不是在唠叨我的编码风格,将与Crockford先生的律师一起去)。也就是说,我对Google的变量名称无能为力......所以,我想我不能100%干净。

I am trying to get my JS code to be 100% JSLint clean (I'm not religious about my coding style, and so will go with Mr. Crockford's counsel). That said, I can't do anything about Google's variables names... so, I guess I can't get 100% "clean."

我发布此处以防我误解了该消息,并且可以采取一些措施来遵守JSLint做法。

I post here in case I've misunderstood the message, and can do something to comply with JSLint practices.

推荐答案

啊,我已经解决了这个...我将使用下划线前缀变量和JSLint命令的语句包装起来禁用,然后重新启用这类错误:

Ah, I've got this handled... I wrap the statements that use the underscore prefixed variables with JSLint commands to disable, then re-enable this class of error:

/*jslint nomen: true*/
... statement(s) with _var ...
/*jslint nomen: false*/

这篇关于JSLint报告“意外的悬空”下划线前缀变量名称中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 03:30