开发者

assistance in resolving jslint errors

I am getting some errors via jslint that I need assistance with:

  1. Bad Escapement:

    replace('/[^a-zA-Z0-9ñÑáÁéÉíÍóÓúÚüÜ¡¿\s+{0}]/g', '')

  2. Empty block:

    $('#myElement').keydown(function (event) { if (allowAlphaNumeric(event)) { } });

  3. 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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜