assistance in resolving jslint errors
I am getting some errors via jslint that I need assistance with:
Bad Escapement:
replace('/[^a-zA-Z0-9ñÑáÁéÉíÍóÓúÚüÜ¡¿\s+{0}]/g', '')
Empty block:
$('#myElement').keydown(function (event) { if (allowAlphaNumeric(event)) { } });
Unexpected use of '|'
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
Anyone have any ideas how I resolve these开发者_StackOverflow中文版?
Bad Escapement:
You're giving replace
a string containing a regular expression literal. You almost certainly want to just make it a regular expression literal:
replace(/[^a-zA-Z0-9ñÑáÁéÉíÍóÓúÚüÜ¡¿\s+{0}]/g, '')
That's certainly the case if the replace
in question is String#replace
, which I'm assuming it is. If it's something else (it would have been handy to know that) and you really want it to be a string, then just make sure you double up any backslashes within the string -- \s
is not a valid string escape, it's a regular expression construct. So you'd want \\s
there so that the string ends up containing the \
followed by the s
. But again, I think you want the literal (where you wouldn't do that).
Empty block:
Put something in the block:
$('#myElement').keydown(function (event) { if (allowAlphaNumeric(event)) { } });
// here -----------------^
Unexpected use of '|'
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
This one looks fine to me syntactically (logically, see note below), since you really do want the bitwise operator there. Just jslint not understanding your intent.
But, um, isn't x | 0
the same as x
? Couldn't you just remove that?
精彩评论