开发者

Why does JSLint report 'bad escapement' on this code?

JSLint is reporting a 'Bad Escapement' error on the following code that I am revi开发者_如何学运维ewing.

var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

var validChars = "\[^\\s" + specialChars + "\]";  //<---JSLint 'Bad Escapement'

Would anyone be able to shed any light on this, and to how it might be resolved?


If you want to put a literal backslash in a string literal you need to double it:

var validChars = "\\[^\\\\s" + specialChars + "\\]"; 

If you're making regexes, it's much easier to use regex literals.


Bad escapement is an ADsafe Violation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜